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
mapM.

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to