From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr 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 BBB48BC6B for ; Wed, 27 Jun 2007 09:22:02 +0200 (CEST) Received: from orion.metastack.com (no-dns-yet.demon.co.uk [80.177.38.218] (may be forged)) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l5R7M1Kh020462 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Wed, 27 Jun 2007 09:22:02 +0200 Received: from treble (cpc2-cmbg6-0-0-cust535.cmbg.cable.ntl.com [81.107.34.24]) (authenticated bits=0) by orion.metastack.com (8.13.4/8.13.3) with ESMTP id l5R7Ej16016657 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Wed, 27 Jun 2007 08:14:46 +0100 From: "David Allsopp" To: References: <20070627044609.6B456BC77@yquem.inria.fr> Subject: Re: [Caml-list] C-like macros in OCaml Date: Wed, 27 Jun 2007 08:21:58 +0100 Organization: MetaStack Solutions Ltd. Message-ID: <00ae01c7b88b$d98ba100$6a7ba8c0@treble> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 In-Reply-To: <20070627044609.6B456BC77@yquem.inria.fr> Thread-Index: Ace4dTcxNralA+wAQLumXbzEPWI4RQAFODFA X-Miltered: at concorde with ID 46821019.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; c-like:01 ocaml:01 c-like:01 enumeration:01 enum:01 26,:98 2007,:98 26,:98 2007,:98 wrote:01 wrote:01 caml-list:01 functions:01 functions:01 macros:01 On Jun 26, 2007, at 6:06 PM, Jonathan Bryant wrote: > On Jun 26, 2007, at 6:00 PM, Raj B wrote: > > Similarly, is there any way of getting a C-like enumeration? e.g. > > > > enum days {Mon = 1, Tue, Wed...} > > You can use a variant and a pair of functions: > > type weekday = > | Monday > | Tuesday > ... > | Sunday You can also use a variant and Obj.magic which turns the two functions into: let weekday_to_int (w : weekday) = Obj.magic w + 1 let int_to_weekday i = if i >= 1 && i <= 7 then (Obj.magic (i - 1) : weekday) else raise ... But this is really dirty and a potential source of bugs... but the result is closer to the "#define" way. David