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 MAA02037; Sat, 28 Sep 2002 12:55:46 +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 MAA01721 for ; Sat, 28 Sep 2002 12:55:45 +0200 (MET DST) Received: from relay.pair.com (relay1.pair.com [209.68.1.20]) by nez-perce.inria.fr (8.11.1/8.11.1) with SMTP id g8SAthD10447 for ; Sat, 28 Sep 2002 12:55:45 +0200 (MET DST) Received: (qmail 9812 invoked from network); 28 Sep 2002 10:55:41 -0000 Received: from node-d8e9cca2-sfo-onnet.worldcom.com (HELO checkerlap.d6.com) (216.233.204.162) by relay1.pair.com with SMTP; 28 Sep 2002 10:55:41 -0000 X-pair-Authenticated: 216.233.204.162 Message-Id: <4.3.2.7.2.20020928033941.03b2eb10@mail.d6.com> X-Sender: checker@mail.d6.com X-Mailer: QUALCOMM Windows Eudora Version 4.3.2 Date: Sat, 28 Sep 2002 03:55:43 -0700 To: caml-list@inria.fr From: Chris Hecker Subject: Re: [Caml-list] Design advice In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk I usually use variants, but it's not like I've been programming caml for much longer than you have. >type, but now I have to convert this to an integer whenever I want to >use the player number as an index. Note that there is a correspondence between variant constructors with no arguments and integers (http://caml.inria.fr/ocaml/htmlman/manual032.html#htoc212), so: type suit = Spades | Hearts | Diamonds | Clubs let suit_to_int (s : suit) = assert (Obj.is_int (Obj.repr s)); ((Obj.magic s) : int) The assert will catch it if you add variables to one of the constructors and then call this. This uses magic, which is bad, but it alleviates you having to type the variant constructors again and possibly make an error in the assocation with the int, which is good. Pick your poison. Chris ------------------- 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