As mentioned in Why does (sum $ takeWhile (<10000000) [1..]) use so much memory? the following does not blow up the memory in ghci :
foldl' (+) 0 $ takeWhile (< 10000000) [1 .. ]
However if I create a file containing :
import Data.List
longList::[Int]
longList = [1 .. ]
result :: Int
result = foldl' (+) 0 $ takeWhile (< 10000000) longList
main = do
print $ result
and load into ghci, then upon running the program the memory consumption blows up. Why is this, and what can I do to fix the program? I am using ghc 7.8.3.
[EDIT]
It does not seem to blow up provided I compile first via ghc Test.hs
. But if I remove all the .hi
and .o
files, and load into ghci via ghci Test.hs
then the memory does blow up.