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
[Caml-list] Generating C stubs
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-05-21 (07:30)
From: John Max Skaller <skaller@o...>
Subject: [Caml-list] Tail recursion detection
I'm in the process of writing a tail recursion detector for 
Felix, and many of the routines are tail recursive (heh!).
However, in a few places, there are multi-way branches
each of which terminate in identical tail calls:

let rec f x y = match .. with
   | .. -> 
      if .. then 
      if .. then
      if .. then
	f x' y'
      else f x' y'
      else f x' y'
      else f x' y'

My question is: how smart is the Ocaml tail call detector?
Can I optimise the above code like:

let rec f x y = 
  let tail () = f x y in
   if .. then
   if .. then
   if then tail()
   else tail()
   else tail()
   else tail()

for example? [More likely, the 'tail' function will
fix arguments which are commonly invariant ..]

[If tail detection is done after inlining,
and the tail() calls are inlined, the tail calls
should be detected even if the tail call detector
is fairly dumb. In that case, how can I be sure
to inline tail() calls?]

John Max Skaller,
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: