I want to write a Haskell program that outputs a prompt and accepts user input on the same line that the prompt was outputted to. In order to do this I believe I need to force evaluation of the function putStr
.
echoWithPrompt :: IO ()
echoWithPrompt = do
putStr "input: "
echo <- getLine :: IO String
putStrLn echo
main :: IO ()
main = do
echoWithPrompt
Running this as is will not print "input: " until after the user has inputted a line. I have tried things like
write <- putStr "input: "
echo <- write `deepseq` getLine :: IO String
or
putStr $! "input: "
to try to force the message to print but to no avail.