Default bufferring behavior
Vyacheslav Akhmechet
coffeemug at gmail.com
Tue Aug 22 23:15:30 EDT 2006
I encountered the following issue last night. Writing a program like this:
main = do putStr "> "
x <- getLine
putStr x
behaves as expected in hugs and ghci (first prints "> ", then waits
for input, then prints the input). However, when compiling and running
an executable via ghc, the behavior was very different. I saw a blank
console screen and when I typed something it was echoed back to me (as
in "> 25") only after I hit enter. This is trivially fixed by
flushing:
main = do putStr "> "
hFlush stdout
x <- getLine
putStr x
or by turning off buffering. Is this the intended behavior? This
problem does not appear when using putStrLn (as it flushes
automatically) and is quite distracting to newbies. To me it looks
like this behavior is at odds with something one can reasonably expect
and bufferring should be turned off by default. What do you guys
think?
Thanks,
- Slava.
More information about the Glasgow-haskell-users
mailing list