I have the following code:
import Control.Monad (unless) import System.IO (isEOF, hFlush, stdout) main :: IO () main = unlessFinished $ do putStr "$ " hFlush stdout getLine >>= putStrLn main where unlessFinished action = isEOF >>= flip unless action
When I compile and run this code, it displays the cursor at the beginning of an empty line and only after I press [Enter] it will display $ and everything that I wrote.
It would seem that getLine is called before putStr "$ " , even if IO monad guarantees that its actions are called in the order in which they are ordered in the code (or I understand what is written here ). So why is this not working correctly?
source share