[Haskell-cafe] Nested unsafePerformIO?
Bas van Dijk
v.dijk.bas at gmail.com
Thu Apr 8 07:36:17 EDT 2010
It looks like your timedIterateIO is too lazy.
When you pass it a function like (+1) what will happen is that a large
chunk of the form ...+1+1+1+1+1 is build up on your heap. When you
finally need its value the large chunk will be evaluated causing it to
push the '1' arguments on the stack. When there are too much '1's your
stack will eventually overflow.
Try evaluating the 'y' before calling timedIterateIO' again as in:
let y = f x
... y `seq` timedIterateIO' t0 y
I think the normal 'iterate' function also has this behaviour:
iterate (+1) 0 !! 10000000
will cause your heap to be filled with lots of +1s and will finally
cause a stack overflow when it tries to evaluate the final value (I
haven't tried it so I may be wrong here).
More information about the Haskell-Cafe