sequence causing stack overflow on pretty small lists

Bryan O'Sullivan bos at
Mon Aug 26 21:05:14 CEST 2013

On Mon, Aug 26, 2013 at 1:46 AM, Niklas Hambüchen <mail at> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Libraries mailing list