From: "David Allsopp" <dra-news@metastack.com>
To: <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] C-like macros in OCaml
Date: Wed, 27 Jun 2007 08:21:58 +0100 [thread overview]
Message-ID: <00ae01c7b88b$d98ba100$6a7ba8c0@treble> (raw)
In-Reply-To: <20070627044609.6B456BC77@yquem.inria.fr>
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
next parent reply other threads:[~2007-06-27 7:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20070627044609.6B456BC77@yquem.inria.fr>
2007-06-27 7:21 ` David Allsopp [this message]
2007-06-26 22:00 Raj B
2007-06-26 22:06 ` [Caml-list] " Jonathan Bryant
2007-06-27 4:10 ` Richard Jones
2007-06-27 7:43 ` Jeremy Yallop
2007-06-27 8:08 ` Loup Vaillant
2007-06-27 12:53 ` Christopher L Conway
[not found] ` <6f9f8f4a0706280037h5f19af5flb764e1c2999b0337@mail.gmail.com>
2007-06-28 7:38 ` Loup Vaillant
2007-06-28 7:44 ` Nicolas Pouillard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='00ae01c7b88b$d98ba100$6a7ba8c0@treble' \
--to=dra-news@metastack.com \
--cc=caml-list@yquem.inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox