Ok, I have a question with regards to IO function that return
things of type IO [a], but where we are supposed to understand
that the list is returned in a lazy way. This sounds perfectly
ok, but I started thinking about it and cant see how it can work.
For example, if I wanted to make my own getContents function
that returns the contents of a file, the following would NOT work:
  
getContents :: Handle -> IO String
getContents h = 
        do x <- hGetChar h
           xs <- getContents h
           return (x:xs)

Well, I mean this would work, but it would not do it lazily. How
can I make it do it lazily? I hunted around in the Hugs libraries (but
this is not a Hugs question!!! ) and found that in the Channel library
there is a function just like this for channels, and somehow to make
it work it uses unsafeInterleaveIO. WHAT the heck is that thing? I
looked at it and cant tell what it does. Thats one question I have. 
The other question I have, is there a way to do this that I can
understand? Maybe using some minimal extensions, maybe you need
forkIO? I thought about this a bit, can cant think of a way just
using forkIO, but somehow I think it should be possible :) 
 Is there a general way to 'lift' laziness into the IO monad? Perhaps
I am just confused though. 

Anyone have any ideas on this on? I would appreciate it!


Still Learing!
Ron.



Reply via email to