[Haskell-cafe] Strictness leak

Ketil Malde ketil+haskell at ii.uib.no
Wed Oct 31 04:22:38 EDT 2007

Jeff Polakow <jeff.polakow at db.com> writes:

> Besides anything else, sequence will diverge on an infinite list. 

Argh, of course.  Thanks!

> It is necessary to compute all of the computations in the list before returning
> any of the pure resulting list.

Replacing sequence with sequence', given as:

> sequence' ms = foldr k (return []) ms
>     where
>       k m m' = do { x <- m; xs <- unsafeInterleaveIO m'; return (x:xs) }

seems to solve it.
If I haven't seen further, it is by standing in the footprints of giants

More information about the Haskell-Cafe mailing list