[Haskell-cafe] Re: Debunking tail recursion

Ilya Tsindlekht eilya497 at 013.net
Sat May 19 11:31:12 EDT 2007


On Sat, May 19, 2007 at 04:10:29PM +0100, Jon Fairbairn wrote:
[...]
> 
> > foldl f z l = case l of
>                 (x:xs) -> foldl f (f z x) xs
>                 [] -> z
> 
> which reveals that foldl in the RHS isn't really the
> leftmost outermost function, but case is -- the tail call is
> to case. It happens that case is a kind of function that
> makes a choice -- it returns one of its arguments but
> doesn't do anything more to it. In a strict language only
> some predefined operators like case and if have this
> property, but lazy languages allow the definition of new
> ones, which is why we need more care when thinking about
> tail calls.
By definition, tail recursive function is recursive function in which
the value returned from a recursive call is immediately returned without
modification as value of the top-level invocation, which is true for
foldl defined as above.
> 
> -- 
> Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk


More information about the Haskell-Cafe mailing list