[Haskell-cafe] Re: Why purely in haskell?

Niko Korhonen niko.korhonen at gmail.com
Fri Jan 11 11:35:58 EST 2008


Actually, here's a better example:

Prelude> foldl (+) 0 [1..1000000]
*** Exception: stack overflow

Prelude Data.List> foldl' (+) 0 [1..1000000]
500000500000

The explanation to what happens here is trivial to Haskell gurus but
completely baffling to newbies. It is difficult to explain to someone
why the first example doesn't work, although at a glance it should. The
virtue of laziness is that allows constructs like [1..1000000], but the
downside is that it can bite you on the backside when you least expect it.

Niko



More information about the Haskell-Cafe mailing list