[Haskell-cafe] Tracking characters and a timestamp ?

Matthew Brecknell haskell at brecknell.org
Thu Apr 5 00:59:17 EDT 2007

Marc Weber:
> main = do
>   lines <- liftM lines getContents
>   mapM_ print lines -- *
> So this example should "hang", as well, shouldn't it?

It would, except for the magic of unsafeInterleaveIO.

It doesn't "hang" because getContents uses unsafeInterleaveIO internally
to return the file contents lazily. If you took the unsafeInterleaveIO
out of getContents, your program would wait for EOF on input before
printing anything to output, as you had been expecting.

Bulat's post showed how to add the same kind of magic into your use of

More information about the Haskell-Cafe mailing list