Non-monolithic version of 'sequence' for IO monad?

Joe English
Mon, 05 Nov 2001 14:23:18 -0800

Is there any way, short of using unsafePerformIO,
to implement a combinator

    f :: [IO a] -> IO [a]

in a way that the the result is produced lazily?

The problem with

    sequence :: (Monad m) => [m a] -> m [a]
    sequence = foldr (liftM2 (:)) (return []) where
	liftM2 f a b = do { a' <- a; b' <- b; return (f a' b') }

is that it consumes the entire input before producing a result.

Thanks for any advice,

--Joe English