English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Re: [Caml-list] ocaml and named constants
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-05-31 (16:34)
From: Brian Rogoff <bpr@b...>
Subject: Re: [Caml-list] ocaml and named constants
On Thu, 31 May 2001, Luc Maranget wrote:
> But I have another remark
> as far a ``manifest constants'' are the issue, Polymorphic
> variants
> (http://caml.inria.fr/ocaml/htmlman/manual003.html)
> seem to do the job.
> After all, provided you do not care much about the actual value of Foo)

Ah, the problem for me is that I really do care about the actual value for 
the constants. It turns out that I may process binary file formats (GDSII
is the canonical example) where I want the name to correspond to a number. 
Of course, I can and do do it by hand (or use P4) by writing the equivalent of 
Ada's 'Pos and 'Val attributes for enumerated types. I would use plain old 
sum types too since I don't need them to be open for extension. It's a bit 
more cumbersome than I'd like it since I have to specify the mapping twice 
(constructor -> integer and integer -> constructor) which is cumbersome.

-- Brian

To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr