
On Mon, Aug 26, 2013 at 12:05:14PM -0700, Bryan O'Sullivan wrote:
On Mon, Aug 26, 2013 at 1:46 AM, Niklas Hambüchen
wrote: This is because sequence is implemented as
sequence (m:ms) = do x <- m xs <- sequence ms return (x:xs)
and uses stack space when used on some [IO a].
This problem is not due to sequence, which doesn't need to add any strictness here. It occurs because the functions in System.Random are excessively lazy. In particular, randomIO returns an unevaluated thunk.
I don't understand this. The same stack overflow occurs with tenmil :: Int tenmil = 10 * 1000 * 1000 main :: IO () main = do list <- replicateM tenmil (return ()) :: IO [()] list `seq` return () "return ()" is not excessiely lazy, is it? Could you explain further? Tom