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
[Caml-list] enums in OCaml?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-06-14 (08:39)
From: Chris Hecker <checker@d...>
Subject: Re: [Caml-list] enums in OCaml?

>So, what's so wrong with just using variables?
>let Accel = 1;;
>let Stop = 0;;
>seems pretty short to write and shortest to use...  Am I missing something
>( elegant | obvious )?  Is that just ugly?

You can't pattern match on variables (even constant nonmutable ones like that).  See the list archives for threads about this.

You have to do this:

match value with
| v when v = accel -> blah
| v when v = stop -> etc

Not very pretty.

If you're going to be using them in code a lot, then I'd just use variants (sum types).  Yes, it'd be best to be able to switch on the constants, but this is apparently hard; see the archive.


Bug reports:  FAQ:
To unsubscribe, mail  Archives: