[Haskell-beginners] stack overflow summing numbers read from a big file

Axel Wegen axel.wegen at gmail.com
Sat Mar 23 13:42:41 CET 2013


When I try to run the following code on a 50M file consisting of one
number per line I receive a `Stack space overflow' error and the program
seems to consume a lot of memory. Why does that happen? And how can I
fix the problem without increasing the Stack with -Ksize hoping that it
will be big enough? Any general advice on processing big files with
Haskell?

-- sumFile.hs
-- adapted from Real World Haskell's SumFile.hs at the beginning of
-- Chapter 8
main = interact sumFile
  where sumFile = show . sum . map read . words

ghc -o sumFile sumFile.hs  
./sumFile < ./numbers   



More information about the Beginners mailing list