[Haskell-cafe] hPutStrLn and hFlush
Stepan Golosunov
stepan at golosunov.pp.ru
Mon Jan 9 11:43:43 EST 2006
On Mon, Jan 09, 2006 at 04:57:51PM +0100, Gracjan Polak wrote:
> Hi all,
>
> A bit strange behaviour with hPutStrLn. Consider following program:
>
> main = do
> handle <- openFile "output.txt" WriteMode
> hPutStrLn handle (unlines contLines2)
> -- hFlush houtput
> where
> contLines2 = flip map [1..2000] $
> \x -> show x ++ " been there done that"
>
> Outputs file which ends with following lines:
>
> 1989 been there done that
> 1990 been there done that
> 1991 been there done that
> 1992 been there done that
> 199
> (END)
>
> So the output is truncated. When I uncomment hFlush, file is fully written.
> Is this expected/documented behaviour?
This is the usual behavior when file is not closed. And example from
http://www.haskell.org/onlinereport/io.html suggests that using hClose
is necessary.
More information about the Haskell-Cafe
mailing list