I type this code into the interpreter and memory is rapidly consumed:
last [1..10^7] `seq` ()
I can't see why this needs more than O(1) space. If i do just (which should be the same, because Show forces weak head normal form, so seq is redundant?):
last [1..10^7]
...it works fine.
I'm unable to reproduce this situation outside the interpreter.
What's going on here?
Here are some test cases: http://hpaste.org/69234
Things to note:
- By running in the interpreter, I load wtf.hs without compiling it, and type
wtf<n>in ghci. - By compiling, I do
ghc --make wtf.hs && ./wtf. lastcan be substituted for asumwith strict accumulator or a function that finds the max element in the list, and the space leak still happens- I haven't seen this behaviour when using
$!instead ofseq. - I tried adding a dummy
()parameter because I thought maybe this is a CAF problem. Changes nothing. - It's probably not a problem with functions on
Enum, because I can reproduce the behaviour withwtf5and later, which don't useEnumat all. - It's probably not a problem with
Num,Int, orInteger, because I can reproduce the behaviour without them inwtf14andwtf16.
I tried reproducing the problem with Peano arithmetic to take lists and integers out of the equation (fetching the at the end of of 10^9), but ran into other sharing/space leak problems I don't understand when trying to implement *.

I think @n.m is right. Nothing is forcing the value in the list, so the 1+1+1+1+... thunk eventually kills space.
I will whip up a quick test.