[Haskell-cafe] Tail-call optimization

ajb at spamcop.net ajb at spamcop.net
Sun Dec 11 21:37:26 EST 2005


G'day all.

Quoting Joel Reymont <joelr1 at gmail.com>:

> Thank you Andrew! Does it have any effect on performance?

Yes, however I believe that GHC can perform this transformation
automatically at high optimisation levels.  Even so, for portability,
it's wise not to rely on your implementation performing specific
high-level transformations for you.

> Is there a speed up of any sort from not passing parameters?

It depends on the implementation.  There is no difference for an
implementation which relies on lambda lifting (e.g. Gofer).  For the
STG machine, which both Hugs and GHC use, it theoretically makes a
difference for the better, though it might not be measurable in
practice.

You can be almost certain that the second version is no worse in
performance, and it's usually more readable.

Cheers,
Andrew Bromage


More information about the Haskell-Cafe mailing list