If I have a possibly endless list of IO-monads, and I'm sure that their subsequent execution will not be affected by other IOs, 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 getContentsto get the effect I want
main = do
inputs <- return . lines =<< getContents
mapM_ putStrLn inputs
but in my application monads are IOnot getLine, but an external function get1 :: IO (Maybe Record). However, this actually brings my point of view, because, apparently, it getContentsuses unsafeIOto 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