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.
7.6.3
. Is it a compiler bug ? Also you may want to start yourghci
usingghci -fobject-code
as stated here.7.6.3
. If you remove all the.hi
and.o
files, and then load into ghci viaghci Test.hs
does the program blow up for you? Thanksghc Test.hs
and then load into ghci it does not blow upghci
. I guess it's best to test these condition not inghci
.