[Haskell-cafe] Re: foldl vs foldl'

Achim Schneider barsoap at web.de
Tue Nov 4 18:31:24 EST 2008

"Daryoush Mehrtash" <dmehrtash at gmail.com> wrote:

> Are there cases (function or list) where the result of foldl (or
> foldr)would be different that foldl' (or foldr')?
Yes, in two cases folds can differ:

a) You've got an infinite list, in which case you don't want to go to
the end of it before starting to return values

b) You don't have infinite memory and thus need things to be strict (or
just don't want to pay the overhead of allocating millions of thunks
for no good reason whatsoever, in case you're lucky enough to have
enough memory for your data)

(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.

More information about the Haskell-Cafe mailing list