From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA18350; Mon, 30 Sep 2002 17:53:36 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA18266 for ; Mon, 30 Sep 2002 17:53:35 +0200 (MET DST) Received: from athlon.baretta.com (host169-68.pool80116.interbusiness.it [80.116.68.169]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g8UFrYD25487 for ; Mon, 30 Sep 2002 17:53:35 +0200 (MET DST) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id 4F3CE27249; Mon, 30 Sep 2002 18:03:24 +0200 (CEST) Message-ID: <3D9875CC.5000707@baretta.com> Date: Mon, 30 Sep 2002 18:03:24 +0200 From: Alessandro Baretta Organization: Baretta srl -- www.baretta.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020826 X-Accept-Language: it, en MIME-Version: 1.0 To: caml-list@inria.fr Cc: Lauri Alanko , Dan Schmidt Subject: Re: [Caml-list] Design advice References: <20020929122730.GA1093@la.iki.fi> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Lauri Alanko wrote: > This doesn't help you much, but you may be interested to know that in > Haskell this wouldn't be much of a problem. You would do simply: > > data Suit = Spades | Hearts | Diamonds | Clubs > deriving (Eq, Ord, Enum, Ix) > > ... > Finally, "Ix" means that the compiler generates some functionality that > is required for a data type to be usable as an array index. And this is > probably the feature that you seem to need. In Haskell, you could have > an array whose _index_ type is Suit. With such an array, there's no fear > of overflowing, because there simply _aren't_ any index values of the > proper type that weren't included in the domain of the array. > > Of course you can get the same safety in ocaml, too, but it just > requires some more work on your part. > > This isn't an unconditional plug for Haskell, mind you. Both Haskell and > ocaml are fine languages, and each has great features that the other > lacks. > > > Lauri Alanko > la@iki.fi type tagged_type = Tag1 of foo | Tag2 of bar | ... class ['a] tagged_array size = object val map = Hashtbl.create size method set index value = Hashtbl.remove map index; Hashtbl.add map index value method get index = Hashtbl.find map index (* any other methods you might need *) end It's not really an array, but it's almost as fast and works very much like one. I think this approach might solve most of Dan's problems. Alex ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners