Hi community,

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.


content :: Int -> IO [Int]
content i = do
fs <- files i
ds <- directories i
fss <- mapM content ds
return $ fs ++ concat fss

files i = return [1..i]

directories i = return [1..i-1]

main = content 1000000 >>= print . take 5


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.
I guess another weakness of this code is the bad performance of "dfs ++ concat fss", but currently I don't care about that.

Thanks for any help
Tim