From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id A9B08BCA8 for ; Thu, 31 Mar 2005 08:32:56 +0200 (CEST) Received: from first.in-berlin.de (dialin-145-254-055-146.arcor-ip.net [145.254.55.146]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j2V6Wsff002653 for ; Thu, 31 Mar 2005 08:32:55 +0200 Received: by first.in-berlin.de (Postfix, from userid 501) id 7E8D4C9690; Thu, 31 Mar 2005 00:29:44 +0200 (CEST) Date: Thu, 31 Mar 2005 00:29:44 +0200 From: Oliver Bandel To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] generic data type -> int function Message-ID: <20050330222944.GB443@first.in-berlin.de> References: <16963.63456.885441.571929@gargle.gargle.HOWL> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.6i X-Miltered: at nez-perce with ID 424B9996.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; oliver:01 bandel:01 oliver:01 in-berlin:01 caml-list:01 enum:01 mtype:01 pairs:01 mtype:01 pairs:01 integers:01 nam:98 nam:98 ...:98 ...:98 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.3 required=5.0 tests=DATE_IN_PAST_06_12, FORGED_RCVD_HELO autolearn=disabled version=3.0.2 X-Spam-Level: On Tue, Mar 29, 2005 at 07:26:02PM -0800, Hal Daume III wrote: > Unsatisfied with any of the solutions offered to me, I threw together a > quick perl script to do this for me. For anyone who wants it, you can get > it at: > > http://www.isi.edu/~hdaume/type_to_enum.pl > > It's very limited in that it has no knowledge of built in types, and type > specs must all be on one line per type, but for my purposes it works > keenly. > > Example input: > > type etype = GPE | LOC | ORG | PER | NAE_e | BOS_e > type mtype = BAR | NAM | NOM | PRE | PRO | OTHER | NAE_m | BOS_m > type pairs = EM of etype*mtype | EE of etype*etype | MM of mtype*mtype > type pairs2 = EP of etype * pairs | MP of mtype * pairs > > > Corresponding output: > > let int_of_etype = function | GPE -> 0 | LOC -> 1 | ORG -> 2 | PER -> 3 | NAE_e -> 4 | BOS_e -> 5 > let int_of_mtype = function | BAR -> 0 | NAM -> 1 | NOM -> 2 | PRE -> 3 | PRO -> 4 | OTHER -> 5 | NAE_m -> 6 | BOS_m -> 7 ...ooops... GPE as well as BAR has the same output-value... ...so... if there is no problem with that kind of similar integers, why don't you use Kims solution?! Ut seemed to me that it has solved your problem, at least in this respect. Ciao, Oliver