1

I am making a program that prompts the user for a line and then prints it to the console. My code looks like this:

main :: IO ()
main = do
  putStr "> "
  result <- getLine
  putStrLn result

The problem is, Haskell's IO is lazy. So this happens:

$ ghc test.hs
[1 of 1] Compiling Main             ( test.hs, test.o )
Linking test ... 
$ ./test
hello
> hello

How can I make my Haskell IO actions perform in the action I write them in?

0 Answers0