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&#39;t fully understand though why it is unsafe. Doesn&#39;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">&lt;<a href="mailto:stephen.tetley@gmail.com" target="_blank">stephen.tetley@gmail.com</a>&gt;</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 &lt;- readLazy<br>
          mapM_ (\x -&gt; putStr $ show x ++ &quot;\n&quot;) $ messages<br>
          return ()<br>
          where<br>
            readLazy :: IO [String]<br>
</div>            readLazy = unsafeInterleaveIO $ do<br>
<div><div></div><div>                         { c &lt;- fancyIORead<br>
                         ; liftM2 (++) (return c) readLazy<br>
                         }<br>
            fancyIORead :: IO [String]<br>
            fancyIORead = return [&quot;aa&quot;,&quot;bb&quot;]<br>
</div></div></blockquote></div><br>
</div>