Version française
Home     About     Download     Resources     Contact us    
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: ketty <kattlachan@g...>
Subject: Re: [Caml-list] Ocaml compiler features
On 1/14/07, Edgar Friendly <thelema314@gmail.com> 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:
http://www.bononia.it/~zack/stuff/hashtbl_ext.ml