caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* RE: Compiler translation of array indexing
@ 2000-01-19 17:33 Simon Peyton-Jones
  2000-01-19 22:50 ` Pierre Weis
  0 siblings, 1 reply; 7+ messages in thread
From: Simon Peyton-Jones @ 2000-01-19 17:33 UTC (permalink / raw)
  To: 'Pierre Weis', dmcclain; +Cc: caml-list

| > 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




^ permalink raw reply	[flat|nested] 7+ messages in thread
* Compiler translation of array indexing
@ 2000-01-18 16:34 David McClain
  2000-01-19 14:25 ` Pierre Weis
  0 siblings, 1 reply; 7+ messages in thread
From: David McClain @ 2000-01-18 16:34 UTC (permalink / raw)
  To: caml-list

I would like to suggest a slightly more expressive form for the translation
of array indexing operators x.(..) and x.[..]. In Dylan these get translated
into message sends to generic function "element" (or "aref" in the case of
multiple indices). 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)

This would allow us to develop modules containing refined versions of get,
set, unsafe_get, and unsafe_set to do whatever would be appropriate for the
object being indexed. Currently, I don't know of any operators named
"module_of" and "type_of" and these might in fact not make much sense given
the vast optimizations performed in the compiler -- there are not unique
tags for disparate data types since the language is type checked at compile
time.

Just some thoughts and wishes...

David McClain, Sr. Scientist
Raytheon Systems Co.
Tucson, AZ





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2000-01-25  8:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-01-19 17:33 Compiler translation of array indexing Simon Peyton-Jones
2000-01-19 22:50 ` Pierre Weis
2000-01-24 17:06   ` Andreas Rossberg
  -- strict thread matches above, loose matches on Subject: below --
2000-01-18 16:34 David McClain
2000-01-19 14:25 ` Pierre Weis
2000-01-19 17:08   ` Markus Mottl
2000-01-19 21:17     ` Pierre Weis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).