If I have a possibly endless list of IO
-monads, and I'm sure that their subsequent execution will not be affected by other IO
s, can I somehow make it lazily ordered (evaluated)?
To clarify my point, here is some pseudo-Haskell code demonstrating what I had in mind:
main = do
inputs <- sequence . repeat $ getLine
mapM_ putStrLn inputs
Now I know that in the above example we can just use getContents
to get the effect I want
main = do
inputs <- return . lines =<< getContents
mapM_ putStrLn inputs
but in my application monads are IO
not getLine
, but an external function get1 :: IO (Maybe Record)
. However, this actually brings my point of view, because, apparently, it getContents
uses unsafeIO
to achieve this lazy effect. My question is what is needed? (If you are interested in what exactly I want to do, refer to this question .)
source
share