An IO Question from a Newbie

Hal Daume III hdaume at ISI.EDU
Fri Sep 12 17:18:22 EDT 2003

This is a buffering problem.  Use hSetBuffering to fix this (see Chapter 3 
in YAHT --  Alternatively, use:

> main = do putStrLn "Type Something:"
>           ...

in which case the "Ln" part will force it to be printed.

 - Hal

On Fri, 12 Sep 2003, Matt O'Connor wrote:

> 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.
> s
> 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.
> Matt

 Hal Daume III                                   | hdaume at
 "Arrest this man, he talks in maths."           |

More information about the Haskell-Cafe mailing list