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
tail rec
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-05-19 (20:19)
From: Jonathan Bryant <jtbryant@v...>
Subject: Re: [Caml-list] tail rec

>>> I have a silly idea. Introduce a new construction:
>>> let tailrec f ..
>>> This is the same as let rec except it checks every direct call to f
>>> is in tail position (and bombs out the compiler if not).

A question I have about tail recursion in general:

let f x = (* Do something *)
let g x = (* Do something *); f x
let h x = (* Do something *); g x

Does the compiler optimize the calls (f x) and (g x) into tail  
calls?  If so, how would the

let railrec f x = ...
let tailrec g x = ...
let tailrec h x = ...

syntax handle/help this?  Or would it hinder it?