An IO Question from a Newbie

Matt O'Connor angagon at
Fri Sep 12 17:27:59 EDT 2003

Hello all.  I'm new to functional programming and Haskell, but have been 
programming in C and Java for a while.  I've been going through the tutorials 
and whatnot on  I've read from the Gentle Introduction to 
Haskell about IO and some of the other stuff and I have a question about it.  

main = do putStr "Type Something: "
          str <- getLine
          putStrLn ("You typed: " ++ str)

When compile and run this code the "Type Something: " isn't displayed until 
the putStrLn.  So there is no prompt.  The output looks like this.

Type Something: You typed: s

But if I change the putStr "Type Something: " to a putStrLn or put a \n at the 
end of the string it displays the text immediately (ie, when I want it to).  
Is there a good reason for this?  Am I doing something wrong?  Or do I need 
to call some kind of standard output flush?  Thanks.

Oh, I'm using ghc.


"Not everone knows Josiah Royce's definition of a liar as a man who 
willfully misplaces his ontological predicates, but everyone who has
ever told a lie will recognize its accuracy."

Ch. 94: Truth - 
"The Great Ideas: A Synopticon of Great Books of the Western World"

More information about the Haskell-Cafe mailing list