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 MAA09670; Mon, 30 Sep 2002 12:34:35 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA09651 for caml-list@pauillac.inria.fr; Mon, 30 Sep 2002 12:34:34 +0200 (MET DST) 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 MAA09252 for ; Mon, 30 Sep 2002 12:23:48 +0200 (MET DST) Received: from porsta.cs.Helsinki.FI (porsta.cs.helsinki.fi [128.214.48.124]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g8UANlD16931 for ; Mon, 30 Sep 2002 12:23:47 +0200 (MET DST) Received: from alkokrunni.cs.Helsinki.FI (sslwrap@localhost [127.0.0.1]) by porsta.cs.Helsinki.FI (8.11.6/8.11.6) with ESMTP id g8UANi920267 for ; Mon, 30 Sep 2002 13:23:46 +0300 Received: from localhost (lealanko@localhost) by alkokrunni.cs.Helsinki.FI (8.11.6/8.11.2) with SMTP id g8UANhJ22586 for ; Mon, 30 Sep 2002 13:23:43 +0300 X-Authentication-Warning: alkokrunni.cs.Helsinki.FI: lealanko owned process doing -bs Received: from la by la.iki.fi with local (Exim 3.35 #1 (Debian)) id 17vdAZ-0000NW-00 for ; Sun, 29 Sep 2002 15:27:31 +0300 Date: Sun, 29 Sep 2002 15:27:30 +0300 From: Lauri Alanko To: caml-list@inria.fr Subject: Re: [Caml-list] Design advice Message-ID: <20020929122730.GA1093@la.iki.fi> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4i Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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) Here "Eq" and "Ord" mean that the compiler generates equality comparison and ordering functions for the datatype. This is basically what ocaml's (=) and compare -functions do. "Enum" means that the compiler generates a bidirectional mapping between your data type and a subset of natural numbers. This is useful if you eg. need to communicate Suit values via an external interface (files, sockets, whatnot). 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 ------------------- 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