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] Does Caml have slow arithmetics ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-07-08 (17:12)
From: brogoff <brogoff@s...>
Subject: Tail calls (Was Re: [Caml-list] Does Caml have slow arithmetics ?)
On Thu, 8 Jul 2004, Luc Maranget wrote:

> > On Thu, Jul 08, 2004 at 11:51:10AM +0200, Andreas Rossberg wrote:
> >
> > Many ocaml programs depend on tail-call elimination, although I don't
> > believe anything in the docs requires it to be done.
> >
> Well, when programming in caml, I use the following rules (which I hope to be
> accurate!)
> + ocamlc does perform tail call elimation
> + ocamlopt does it less often. Namely, calls in tail position
>   become real tail calls when all their arguments are passed in registers.
>   (This does not apply to self-tail calls which are always optimized)

In my own code the self tail call is by far more

   let rec loop params accum =
      if finished params accum then
         result params accum
        loop (update_params params) (update_accum params accum)

is by far more the most common, so much so that that idiom is "under finger".
Usually params takes up one or two arguments. Anyone have good examples
where this limitation leads to significantly "uglier" code?

The limitation you describe should be well doumented, but is not yet annoying
to me. I'll need to write some tests and check the assembly output on the
Linux machines I have access to.

More annoying is the lack of some way to get the "tail recursion modulo cons"
capability directly in the language without needing to use Obj functionality.

-- Brian

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