From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by yquem.inria.fr (Postfix, from userid 18041) id E58AFBC57; Tue, 8 Jun 2010 11:36:51 +0200 (CEST) Date: Tue, 8 Jun 2010 11:36:51 +0200 To: David Allsopp Cc: 'bluestorm' , caml-list@yquem.inria.fr, 'W Dan Meyer' Subject: Re: [Caml-list] Converting variants with only constant constructors to integers Message-ID: <20100608093651.GA8296@yquem.inria.fr> References: <4C0D3557.1020200@gmail.com> <010d01cb0672$09f3eb90$1ddbc2b0$@romulus.metastack.com> <4C0D4C88.4070102@gmail.com> <877hma78xf.fsf@gmail.com> <013a01cb06de$32c6d930$98548b90$@romulus.metastack.com> <015201cb06ea$f06adc00$d1409400$@romulus.metastack.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <015201cb06ea$f06adc00$d1409400$@romulus.metastack.com> User-Agent: Mutt/1.5.9i From: maranget@yquem.inria.fr (Luc Maranget) X-Spam: no; 0.00; variants:01 constructors:01 integers:01 maranget:01 maranget:01 compiler:01 hashtable:01 compiler:01 lookup':01 --luc:01 ocamlopt:01 -dlambda:01 compilation:01 compile:01 luc:01 > 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.