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: David Mentre <David.Mentre@i...>
Subject: Re: [Caml-list] enums in OCaml?
leary@nwlink.com writes:

> I'm looking for something that would do the right thing when I do:
> 
> printf ( "%d 23", Accelerate );; (* sorry if my syntax is off, I haven't
> gotten too far with it yet *)

Probably something like:

# type enum = Accelerate | Other;;
type enum = Accelerate | Other
# let int_enum e =           
  match e with
  | Accelerate -> 1
  | Other -> 0;;
val int_enum : enum -> int = <fun>
# Printf.printf "%d 23\n" (int_enum Accelerate);;
1 23
- : unit = ()

But without further context, it is difficult to guess what you want
(i.e. do the right thing).

Maybe you should have a look at source code of standard libraries. They
are remarkably concise and well written.

For example, operations on lists (List module):
http://camlcvs.inria.fr/cgi-bin/cvsweb.cgi/ocaml/stdlib/list.ml?rev=1.27&content-type=text/x-cvsweb-markup

d.
-- 
 David.Mentre@inria.fr -- http://www.irisa.fr/prive/dmentre/
 Opinions expressed here are only mine.
-------------------
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