On 13-05-2011, OGrandeDiEnne <[email protected]> wrote:
> Hello people,
> considering that
>
> 1) tail recursion is faster than non-tail-recursion (because it does
> not have put a call in the stack for each iteration)
>
> 2) it is possible to convert any non-tail-recursive function into a
> tail-recursive function
>
> Is worth it to rewrite functions in tail-recursive ? Is Ocaml compiler
> already converting my non-tail recursive functions into tail version,
> when compiling?
>

Is it worth ? not always
Is Ocaml compiler ... ? I don't think so

As you stated, converting non-tail recursive to tail recursive made the
code a little more complex. Another argument is the expected number of
recursive calls. If you know that you will have a limited number of
call (e.g. 1024) and that non-tail recursive form is more clear, you
should pick the non-tailrec. 

My 2 cents,
Sylvain Le Gall
-- 
My company: http://www.ocamlcore.com
Linkedin:   http://fr.linkedin.com/in/sylvainlegall
Start an OCaml project here: http://forge.ocamlcore.org
OCaml blogs:                 http://planet.ocamlcore.org


-- 
You received this message because you are subscribed to the Google Groups 
"ocaml-developer" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/ocaml-developer?hl=en
For other OCaml forums, see http://caml.inria.fr/resources/forums.en.html

Reply via email to