[Haskell-cafe] Bug in "Haskell for C programmers" tutorial?

Glynn Clements glynn at gclements.plus.com
Sun Jan 1 07:10:10 EST 2006


Cale Gibbard wrote:

> You shouldn't have to flush output manually. Which implementation are
> you using? Try importing System.IO and doing:
> hGetBuffering stdout >>= print
> and see what gets printed. It should be "NoBuffering".

The buffering for stdout should be LineBuffering if stdout is a
terminal and BlockBuffering otherwise. The buffering for stderr should
always be NoBuffering.

> If for whatever
> reason it's not, you can set it to that at the start of your programs
> with hSetBuffering stdout NoBuffering

I would suggest using an explit hFlush after each putStr rather than
disabling buffering altogether, as disabling buffering will result in
putStr etc calling write() once per character, which is very
inefficient.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the Haskell-Cafe mailing list