Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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.

Chris

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr