[Haskell-cafe] Tracking characters and a timestamp ?

Bulat Ziganshin bulat.ziganshin at gmail.com
Wed Apr 4 18:58:54 EDT 2007

Hello Matthew,

Thursday, April 5, 2007, 2:00:03 AM, you wrote:

>> main = do
>>   hSetBuffering stdin NoBuffering
>>   hGetContents stdin >>= mapM addTimeCode >>= mapM_ handleChar
>> It seems to wait till the end of the infinite list. Why?

> The sequencing imposed by the IO monad means that the first mapM must
> complete before the second can start. To see this, you can try the
> following:

or, alternatively, replace first mapM_ with unsafeInterleavedMapM:

unsafeInterleavedMapM f (x:xs) = do a <- f x
                                    as <- unsafeInterleaveIO (unsafeInterleavedMapM f xs)
                                    return (a:as)

(not tested)

Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com

More information about the Haskell-Cafe mailing list