<pre><span class="kr">Hi community,<br><br>In the following code, the main function only wants to print the first 5 numbers of a huge list. But since the computation is not lazy, this doesn&#39;t work in a satisfactory way.<br>
<br><br></span><span class="nf">content :: Int -&gt; IO [Int]<br>content i = do<br>  fs  &lt;- files i<br>  ds  &lt;- directories i<br>  fss &lt;- mapM content ds<br>  return $ fs ++ concat fss<br><br>files i = return [1..i]<br>
<br>directories i = return [1..i-1]<br><br>main = content 1000000 &gt;&gt;= print . take 5<br></span><br><br>Now I&#39;d like to know if it&#39;s possible to make this &quot;IO&quot; lazy, using unsafeInterleaveIO. I tried to do it, failed. Perhaps someone can help.<br>
I guess another weakness of this code is the bad performance of &quot;d<span class="nf">fs ++ concat fss</span>&quot;, but currently I don&#39;t care about that.<br><br>Thanks for any help<br>Tim<br><br></pre>