RE: Compiler translation of array indexing

From: Simon Peyton-Jones (simonpj@microsoft.com)
Date: Wed Jan 19 2000 - 18:33:27 MET

  • Next message: Pierre Weis: "Re: Compiler translation of array indexing"

    | > Instead of translating as in OCAML to Array.get and
    | > Array.set, they could be translated into some equivalent to
    | >
    | > x.(n) -> module_of(type_of x).get(x, n)
    |
    | There are strong theoretical difficulties to obtain a type_of function
    | embedded into a statically & strongly type checked language such as
    | Caml.

    It's perhaps worth mentioning that one way of achieving
    this effect is to use type-driven overloading, as Haskell
    does. One could say

            class Array a where
              (.) :: a elt -> Int -> elt
              ... more operations...

    (Here 'a' is a type variable ranging over type constructors
    of kind *->*.)

    Now for each type (constructor) T that you want to make an
    instance of Array, you would say

            instance Array T where
              (.) = ...your implemention of indexing for T...

    Such type classes are, however, fully implemented in Haskell.
    However, type classes (not to be confused with object oriented
    classes as in OCaml) form quite a large design space, and its
    interaction with OCaml classes and modules are quite unknown (to me
    anyway).

    There's a paper about the type-class design space at
            http://research.microsoft.com/~simonpj/papers/multi.ps.gz

    Simon



    This archive was generated by hypermail 2b29 : Wed Jan 19 2000 - 22:00:43 MET