Version française
Home     About     Download     Resources     Contact us    
Browse thread
Converting variants with only constant constructors to integers
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: maranget@y...
Subject: Re: [Caml-list] Converting variants with only constant constructors to integers
> Of course, if you have the following:
> 
> type t = A | B | C
> let int_of_t = function
>   A -> 0
> | B -> 1
> | C -> 2
> 
> Then in fact I believe that the compiler already converts that to a
> hashtable lookup instead of a sequence of jumps..

The compiler does not convert the above code to 'hashtable lookup'.


--Luc

PS>

To have a look at produced code.
* put your (Caml) code in some file say a.ml;
* compile as ocamlopt -S a.ml
* look at a.s

You can also use various options, such as -dlambda or -dcmm, to
see intermediate stages of the compilation process.