[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Robert Fischer <robert.fischer@S...> |
| Subject: | Re: [Caml-list] tail rec |
I'm with Brian on this, although it the "tailrec" specification needs to
be optional. I use tail recursion by accident a lot when I'm coding
("Oh, hey, I guess this is tail recursive. Nifty!"), and I would be
really annoyed to have to think about whether my recursion is tail
recursive or not every time I use it.
~~ Robert.
>
> A better proposal would be one where the call itself is marked as a
> tailcall, and bombs out if that call isn't. Maybe something like:
>
> let rec loop i s =
> if i > 0 then
> tailcall loop (i-1) (s+i) (* force this to be a tailcall *)
> else s
> in
> let t = 2 * (loop n 0) in ... (* not a tail call, and that's OK *)
>
> At which point I'm neutral on the idea. The rules for what is or
> isn't a tail call are not complicated. On the other hand, it's a
> little bit of extra correctness for not much cost.
>
> Brian