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.
  • last can be substituted for a sum with 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 of seq.
  • 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 with wtf5 and later, which don't use Enum at all.
  • It's probably not a problem with Num, Int, or Integer, because I can reproduce the behaviour without them in wtf14 and wtf16.

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 *.

Edit
Report