Browse thread
RE: Compiler translation of array indexing
- Simon Peyton-Jones
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Simon Peyton-Jones <simonpj@m...> |
| Subject: | 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