Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Ocaml compiler features
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Edgar Friendly <thelema314@g...>
Subject: Re: [Caml-list] Ocaml compiler features
ketty wrote:
> On 1/14/07, Edgar Friendly <> wrote:
>> That gives me what I've asked for at the moment, but I really want
>> arrays indexed by atomic variant types in a type-safe way.  i.e. so I
>> could do:
>> type food = Carrot | Apple | Pizza | Coke | Sushi
>> let in_supply = Super_array.create food 0
>> in_supply.(Coke) <- 20
>> for f in food'range do
>>         printf "%s - %d" f'name in_supply.(f)
>> done
> What you really want is a mapping from a variant type to elements of
> data. We already have the Map and Hashtbl modules for that. Although
> it would be nice with some syntactic sugar for dealing with them.
> There seems to be an old syntax extension for hashtables here:
Yes to the first sentence, I think no on the second.  Map and Hashtbl
are very good, but I think I really want an array.  For an ('a, 'b) Map,
this is for situations where the set of 'a is fixed at design time, I
don't see the overhead of Maps and Hashtbls being appropriate.  Atomic
variants already have unique ids from 0 to n-1, so they seem quite
appropriate for this kind of task.