English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    
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: -- (:)
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, mailto:skaller@ozemail.com.au
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.
voice:61-2-9660-0850




-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners