I am playing with IO monad and learning to harness side effects in Haskell and it seems like I got it wrong.
Consider the following code:
main = do
putStr "test"
getLine
return ()
My understanding here is that do
"glues" three IO monads into one. My assumption is that they will be executed in sequence, i.e. "test" will be printed first, then line read, and then dummy return ()
will produce ()
However, when I run compiled app it always waits for line to be read before printing "test".
Reordering putStr
/getLine
does nothig. "Unwrapping" value from IO monad, like this:
main = do
_ <- putStr "test"
_ <- getLine
return ()
... does not change the result either.
What am I missing here? How to enforce order on IO actions?