[Haskell] putStr is not evaluated in the correct order

Andreas S andreas_s at hotmail.com
Sat Sep 2 19:51:32 EDT 2006


Hello, i've got a newbie question to ask. I'd like to ask for user input in 
the same line as the prompt. I found this example on the web
main = do
   putStr "Who are you? "
   name <- getLine
   putStrLn ("Hello, " ++ name)

This works find in ghci, but the compiled code (ghc 6.4.2) executes getLine 
first before executing putStr. Instead of:
Who are you? myself
Hello, myself

I got:
myself
Who are you? Hello, myself

I'm new with haskell, so I can't be too sure about this, but it seems from 
putStr implementation in Prelude, putStr should be executed first.

Why are they different? And if they are suppose to be different, then how to 
put prompt and input on the same line for the compiled code?

Thank you in advance
-andre




More information about the Haskell mailing list