1

I am learning Haskell and I would like to know what does hSetBuffering stdin LineBuffering mean and if there are other commands of this style in Haskell.

chi
  • 111,837
  • 3
  • 133
  • 218
  • Are you sure it's `stdin` and not `stdout`? Also see the [documentation](http://hackage.haskell.org/package/base-4.8.2.0/docs/System-IO.html#v:hSetBuffering). – chi May 03 '16 at 22:05

1 Answers1

3

The LineBuffering mode for stdin will prevent the application from processing the input until end-of-line character is encountered. Basically, it means, your app won't see the characters until you hit Return. Usually, this is the default mode for Terminal input. The other two are NoBuffering and BlockBuffering.

See this answer for more details: Haskell default io buffering

Why do we need buffering? Buffering enables for more efficiently processing data. Instead of feeding the input one byte at a time, it is more efficient to do that in blocks. For Terminal input, the most natural size is one line at a time, because this is how usually an interactive command line application work: consume a line, process it, and present some response.

Some useful info here: http://wcipeg.com/wiki/I/O_buffering

Here is more involved explanation: https://www.quora.com/In-C-what-does-buffering-I-O-or-buffered-I-O-mean

Community
  • 1
  • 1
Tair
  • 3,779
  • 2
  • 20
  • 33