[Haskell] lazy printing
Glynn Clements
glynn.clements at virgin.net
Fri Sep 10 11:10:20 EDT 2004
Serge D. Mechveliani wrote:
> > Haskell is outputting lazily, but by default stdout is set to
> > LineBuffering - for efficiency, a line is only written to stdout
> > once it is complete. Try adding "\n" to the end of the "min2 ="
> > line to see what I mean.
> > To get the behaviour you describe, add import IO and
> > hSetBuffering stdout NoBuffering >> to the start of your main function.
>
>
> ( and what if it also aplies writeFile "log" ? )
Streams which are associated with files are fully-buffered by default,
so writeFile would generate the output in blocks. If you wanted to
change the buffering, you would have to open the file yourself so that
you could get at the descriptor, e.g.
handle <- openFile "log" AppendMode
hSetBuffering handle NoBuffering
hPutStr handle string
hClose handle
--
Glynn Clements <glynn.clements at virgin.net>
More information about the Haskell
mailing list