From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 2341BBC84 for ; Thu, 24 Mar 2005 17:38:42 +0100 (CET) Received: from vapor.isi.edu (vapor.isi.edu [128.9.64.64]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j2OGceov005643 for ; Thu, 24 Mar 2005 17:38:41 +0100 Received: from albini.isi.edu (albini.isi.edu [128.9.216.111]) by vapor.isi.edu (8.11.6p2+0917/8.11.2) with ESMTP id j2OGcLs11486 for ; Thu, 24 Mar 2005 08:38:21 -0800 (PST) Date: Thu, 24 Mar 2005 08:38:21 -0800 (PST) From: Hal Daume III To: Caml Mailing List Subject: generic data type -> int function Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-ISI-4-38-10-MailScanner: Found to be clean X-MailScanner-From: hdaume@isi.edu X-Miltered: at concorde with ID 4242ED10.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; integers:01 ...:98 functions:01 int:01 int:01 data:02 data:02 maths:02 talks:02 let:03 let:03 generic:07 edu:07 edu:07 function:08 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: Hi all -- Is there a straightforward way (or a built in function, or...) to automatically map an enumerated data type to integers (and back, if possible, but that's not strictly necessary). In particular, I need something like: type a = A | B | C | D type b = E | F | G type c = H of a | I of b and I would like to automatically have three functions: let a_to_int = function A -> 0 | B -> 1 | C -> 2 | D -> 2 let b_to_int = function E -> 0 | F -> 1 | G -> 2 let c_to_int = function H a -> a_to_int a | I b -> 3 + b_to_int b obviously in this case it's simple, but if now i add a "D2" to 'a', everything gets screwed up. Is there a build in magic function that will do this, or some way to do this otherwis (like with camlp4 or something)? Thanks in advance -- - Hal -- Hal Daume III | hdaume@isi.edu "Arrest this man, he talks in maths." | www.isi.edu/~hdaume