Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
What is a match statement translated into?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-08-18 (07:42)
From: Jacques GARRIGUE <garrigue@m...>
Subject: Re: [Caml-list] What is a match statement translated into?
From: Joel Reymont <>

> Is pattern-matching code in OCaml expanded into threaded code (pre- 
> computed branch table) or something analogous to the C switch  
> statement (lots of branching)?

I do not understand your description of C compilation: this certainly
depends a lot on the compiler and the optimization level.
OCaml does different things according to the data matched, using a
table when it is compact enough, or branches otherwise. So there is
no uniform answer, just that it is rather optimized.

> How do I find out?
> I suspect this should be quite optimized but I haven't tried dumping  
> disassembling native-compiled OCaml yet and I wonder if there's a  
> simpler approach.

No need to disassemble: you can just dump the assembler with the -S
flag. And this is probably the most instructive approach, as the
compiler itself is quite involved.

Jacques Garrigue