Version française
Home     About     Download     Resources     Contact us    
Browse thread
generic data type -> int function
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Oliver Bandel <oliver@f...>
Subject: Re: [Caml-list] generic data type -> int function
On Tue, Mar 29, 2005 at 07:26:02PM -0800, Hal Daume III wrote:
> Unsatisfied with any of the solutions offered to me, I threw together a 
> quick perl script to do this for me.  For anyone who wants it, you can get 
> it at:
> 
>   http://www.isi.edu/~hdaume/type_to_enum.pl
> 
> It's very limited in that it has no knowledge of built in types, and type 
> specs must all be on one line per type, but for my purposes it works 
> keenly.
> 
> Example input:
> 
> type etype = GPE | LOC | ORG | PER | NAE_e | BOS_e
> type mtype = BAR | NAM | NOM | PRE | PRO | OTHER | NAE_m | BOS_m
> type pairs = EM of etype*mtype | EE of etype*etype | MM of mtype*mtype
> type pairs2 = EP of etype * pairs | MP of mtype * pairs
> 
> 
> Corresponding output:
> 
> let int_of_etype = function | GPE -> 0 | LOC -> 1 | ORG -> 2 | PER -> 3 | NAE_e -> 4 | BOS_e -> 5
> let int_of_mtype = function | BAR -> 0 | NAM -> 1 | NOM -> 2 | PRE -> 3 | PRO -> 4 | OTHER -> 5 | NAE_m -> 6 | BOS_m -> 7


...ooops...  GPE as well as BAR has the same output-value...
...so... if there is no problem with that kind of similar integers,
why don't you use Kims solution?!
Ut seemed to me that it has solved your problem, at least in this respect.

Ciao,
   Oliver