Hi Stephen<div><br></div><div>Thank you very much, this indeed does the trick!</div><div>Using UnsafeIO, however, leaves a creepy unsafe feeling...</div><div>I don't fully understand though why it is unsafe. Doesn't hGetContents do the exact same thing (i.e. reading from IO returning a lazy string) but does not require UnsafeIO.</div>
<div><br></div><div>Fabian<br><br><div class="gmail_quote">On Wed, Feb 24, 2010 at 4:38 PM, Stephen Tetley <span dir="ltr"><<a href="mailto:stephen.tetley@gmail.com" target="_blank">stephen.tetley@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Fabian<br>
<br>
You need to yield with unsafeInterleaveIO to allow some of the list to<br>
be be consumed.<br>
<br>
Something like this (which never terminates of course, but do produce output):<br>
<br>
<br>
import System.IO.Unsafe<br>
<div>import Control.Monad<br>
<br>
main = do messages <- readLazy<br>
mapM_ (\x -> putStr $ show x ++ "\n") $ messages<br>
return ()<br>
where<br>
readLazy :: IO [String]<br>
</div> readLazy = unsafeInterleaveIO $ do<br>
<div><div></div><div> { c <- fancyIORead<br>
; liftM2 (++) (return c) readLazy<br>
}<br>
fancyIORead :: IO [String]<br>
fancyIORead = return ["aa","bb"]<br>
</div></div></blockquote></div><br>
</div>