Some compilers (e.g. SMLNJ) do rewrite all programs into continuation passing style in order to make all calls tail calls and eliminate the stack entirely but the advantage is robustness (no stack overflows) and not performance. Converting recursive functions into tail recursive form typically slows them down because the data stored on the stack is moved into the heap, where allocation and collection is slower.
You might like to try pa_monad in OCaml or asynchronous workflows in F# because they make it easy to write code in continuation passing style by hand using monadic syntax. However, they are only used for a few specific applications and have not caught on for more general programming. Cheers, Jon. > -----Original Message----- > From: [email protected] [mailto:ocaml- > [email protected]] On Behalf Of OGrandeDiEnne > Sent: 13 May 2011 11:52 > To: ocaml-developer > Subject: [ocaml-developer 213] Writing fast (tail-)recursive calls > > 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? > > Since this conversion can be made by a compiler, why bother to rewrite ? Tail- > recursive code can be harder to reason about. > > -- > 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 ocaml-developer- > [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 -- 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
