Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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
> (
> 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  Archives: