[Haskell-cafe] Re: Debunking tail recursion

Jon Fairbairn jon.fairbairn at cl.cam.ac.uk
Sat May 19 16:16:46 EDT 2007


Ilya Tsindlekht <eilya497 at 013.net> writes:

> 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.

Sure. Did I say otherwise?

-- 
Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk



More information about the Haskell-Cafe mailing list