Browse thread
OCaml troll on Slashdot
-
Karl Zilles
-
Oliver Bandel
-
Michael Vanier
-
Jon Harrop
-
Yoann Padioleau
- Jon Harrop
- Paul Argentoff
- Paul Argentoff
-
Yoann Padioleau
-
Jon Harrop
- Yoann Padioleau
-
Michael Vanier
- Richard Jones
-
Oliver Bandel
[
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: | Oliver Bandel <oliver@f...> |
| Subject: | Re: [Caml-list] OCaml troll on Slashdot |
On Wed, Mar 16, 2005 at 09:43:42AM -0800, brogoff wrote: > On Wed, 16 Mar 2005, Jacques Garrigue wrote: > > From: Yoann Padioleau <padiolea@irisa.fr> > > > Jon Harrop <jon@ffconsultancy.com> writes: > > > > In OCaml, non-tail-recursive functions are often faster than their tail > > > > recursive equivalents for small inputs (e.g. short lists). > > > > > > really ? why ? > > > > Because tail-recursive versions do some extra work to ensure > > tail-recursiveness. For instance building a list in reverse order, and > > converting it back with List.rev at the end. This only pays off for > > huge lists. > > No doubt the implementors will want me guillotined for bringing this up again, > but using the (still functional!) set_cdr! tail recursive functions, which do > *not* reverse the list, are always faster than the non tail recursive > list functions, even for small lists, at least in my experience. And I experienced, that adding a "_rev" at the end of a function often makes more sense than adding a List.rev inside. Often some code produces a list and gives it to a function that again creates a list, based on that data. Then "_rev"^2 means _orig and all is going well. If there are an odd number of "_rev"-functions, a List.rev can be added *THEN* (instead of always feel the necessity to provide "_orig"-functions instead of "_rev"-functions. Ciao, Oliver