
11 Jan
2008
11 Jan
'08
4:35 p.m.
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