On Sun, Mar 24, 2013 at 9:04 PM, Axel Wegen <axel.wegen@gmail.com> wrote:
mukesh tiwari <mukeshtiwari.iiitm@gmail.com> writes:
> It seems like the sum function is causing the stack overflow[1].
Graham Gill <math.simplex@gmail.com> writes:
> I think the problem is with laziness in the accumulator of "sum".
> The prelude "sum" is defined as

`Real World Haskell' actually has a warning regarding the use of
Prelude's foldl, the space leaks in causes and how to force evaluation
using `seq' in Chapter 4 under the headings `Left Folds, Laziness, and
Space Leaks' and `Avoiding Space Leaks with seq'. It just slipped my
mind, and I had the wrong assumption of the `sum' function.


Well actually, you wouldn't run into this problem if you compiled with optimization options (ghc -O2 -o sumFile sumFile.hs) since the strictness analyzer is pretty good at spotting strict sums.

--
Jedaï