<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't work in a satisfactory way.<br>
<br><br></span><span class="nf">content :: Int -> IO [Int]<br>content i = do<br> fs <- files i<br> ds <- directories i<br> fss <- 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 >>= print . take 5<br></span><br><br>Now I'd like to know if it's possible to make this "IO" 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 "d<span class="nf">fs ++ concat fss</span>", but currently I don't care about that.<br><br>Thanks for any help<br>Tim<br><br></pre>