[Haskell-cafe] Lazy IO with recursive reads?
Fabian Roth
fabian.roth at gmail.com
Wed Feb 24 08:53:32 EST 2010
Hi all,
I am trying to read structured data from a socket and return a lazy list of
records. However, the socket reading operation seems to be strict and never
returns (until stack overflow). Here's some simplified code to reproduce the
problem:
--------------------
import Control.Monad
main = do messages <- readLazy
mapM_ (\x -> putStr $ show x ++ "\n") $ messages
return ()
where
readLazy :: IO [String]
readLazy = do c <- fancyIORead
liftM2 (++) (return c) readLazy
fancyIORead :: IO [String]
fancyIORead = return ["aa","bb"]
--------------------
In my implementation fancyIORead reads blocks from the socket and returns a
list of records.
But it seems readLazy doesn't ever return.
What could be the problem here?
Also, if anyone has a better solution to write this thing, pls let me know.
Thanks!
Fabian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100224/dcba7ae1/attachment.html
More information about the Haskell-Cafe
mailing list