Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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
      else
        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 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