[Haskell-beginners] stack overflow summing numbers read from a big file
chaddai.fouche at gmail.com
Mon Mar 25 10:30:50 CET 2013
On Sun, Mar 24, 2013 at 9:04 PM, Axel Wegen <axel.wegen at gmail.com> wrote:
> mukesh tiwari <mukeshtiwari.iiitm at gmail.com> writes:
> > It seems like the sum function is causing the stack overflow.
> Graham Gill <math.simplex at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners