English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Reporting on sucess/failure of tail recursion
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-12-02 (09:29)
From: basile@s...
Subject: Re: [Caml-list] Reporting on sucess/failure of tail recursion

> Say I have a file containing a number of Ocaml functions.

> We all know the advantages of tail recursive functions over non-tail
> recursive ones and some of us know if a simple function is tail
> recursice just by looking at it. However, for more complex functions
> it would be really nice if there was a compiler mode that could print
> which recursive functions in a file were tail recursive and which were
> not.

Functions are not tail-recursive, but function *calls* are (or not)
tail-recursive. I mean that a given function may have both tail
and non-tail [-recursive] calls.

Maybe what you are dreaming of is an extension of the -dtypes flag (to
ocamlc) which not only computes the type of each expression,
but also flags each function *call* as a tail (or not a tail) call. I do
agree it would be quite useful (but my knowledge of ocaml internals make
me think that it is in principle easy, but in practice would require a lot
of changes within the compiler, since tail-rec detection is done in passes
near the backend, after the typing.).

We could even dream of a let tailrec language construct which behaves like
let rec but checks that each recursive call to the function is in fact a

All this is in principle easy to do, but I understand that it might
require a significant amount of work which is not the priority of INRIA
Cristal team (which is a team of researchers, not of engineers).


Basile Starynkevitch http://starynkevitch.net/Basile

PS: I've currently got ADSL problems so have difficulties to read my emails.