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
Warning on not-tail recursive functions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-08-04 (12:34)
From: Oliver Bandel <oliver@f...>
Subject: Re: [Caml-list] Warning on not-tail recursive functions
Zitat von Brian Hurt <>:

> On Sat, 4 Aug 2007, wrote:
> > Hello,
> >
> > Please, knows someone if "ocamlopt" can print a warning message when a
> > recursive function is not tail recursive, and code with the "jmp"
> > optimization has not been generated?.
> The problem is that I often write recursive functions which are not tail
> recursive, and that's OK.

Well, during I've learned on tail-recursion I have habituized to always
write functions tailrecursive, so that when I want to try a non-tailrec
function, I really have to think a log about it...


It's only a way of what one is used to do very often.
If you get accustomed to tailrec function writing,
then it's "natural".

Before I knew how to write tailrec code, it was the other way around
and I had to tjink a lot about how to get it tailrec.

> The rules for what is or is not tail recursive are pretty simple.  Boiled
> down, they are:
> 1) The tail call must not be within a try expression
> 2) You can not do anything except return, uninspected and unmodified, the
> returned value from the call.

What ist with a

   ignore (maybe_tailcall())


Does ignore REALLY ignore the values (does not generate them), so that
this call is like a true tail-call, or will the maybe_tailcall
generate and give back results to the ignore-call and then
ignore throws away the stuff (then it would be NO tailcall).