HaskellWiki

Haskell | Wiki community | Recent changes
Random page | Special pages

 

Not logged in
Log in | Help

Request an account if you don't have one.

Tail recursion

Categories: Glossary | Idioms

A recursive function is tail recursive if the final result of the recursive call is the final result of the function itself. If the result of the recursive call must be further processed (say, by adding 1 to it, or consing another element onto the beginning of it), it is not tail recursive. Note that foldl is always tail recursive.

With that said, tail recursion is not that useful of a concept in a lazy language like Haskell. The important concept to know in Haskell is guarded recursion, where any recursive calls occur within a data constructor (such as foldr, where the recursive call to foldr occurs as an argument to (:)). This allows the result of the function to be consumed lazily, since it can be evaluated up to the data constructor and the recursive call delayed until needed.

Source

Retrieved from "http://haskell.cs.yale.edu/haskellwiki/Tail_recursion"

This page has been accessed 1,181 times. This page was last modified 21:37, 25 March 2009. Recent content is available under a simple permissive license.