Im reading this https://wiki.haskell.org/Foldr_Foldl_Foldl%27, but when I try to replicate code such as
foldl k = go
where
go z [] = z
go z (x:xs) = let z' = k z x
in foldl k z' xs
sum2 = foldl (+) 0
try2 = sum2 [1..10000000]
My laptop hangs for a while and evaluates it rather than return a stackoverflow as expected.
Even when I try foldr (+) 0 [1..1000000], I fail to get a stackoverflow unless I increase the size of the list.
Has something changed since the article was written? Any ideas?
I'm loading the file with :l folds.hs, running with stack ghci. I tried the following to reduce my stack size but maybe it was an incorrect way.
stack ghci +RTS -K2M -RTS
Stack limit has been increased to 80% of physical memory by default. For setting the option with stack
, use stack ghci --ghci-options="+RTS -K2M"
. I did get the overflow this way on GHC 8.8.4.