From 0210db9aaa0c95be724258c74ce1dbc4b438fbe6 Mon Sep 17 00:00:00 2001 From: Ross Paterson Date: Tue, 7 Nov 2006 14:03:59 +0000 Subject: [PATCH] redefine writeFile and appendFile using withFile --- System/IO.hs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/System/IO.hs b/System/IO.hs index a7552f5..f45e51d 100644 --- a/System/IO.hs +++ b/System/IO.hs @@ -299,8 +299,7 @@ readFile name = openFile name ReadMode >>= hGetContents -- | The computation 'writeFile' @file str@ function writes the string @str@, -- to the file @file@. writeFile :: FilePath -> String -> IO () -writeFile f txt = bracket (openFile f WriteMode) hClose - (\hdl -> hPutStr hdl txt) +writeFile f txt = withFile f WriteMode (\ hdl -> hPutStr hdl txt) -- | The computation 'appendFile' @file str@ function appends the string @str@, -- to the file @file@. @@ -312,8 +311,7 @@ writeFile f txt = bracket (openFile f WriteMode) hClose -- > main = appendFile "squares" (show [(x,x*x) | x <- [0,0.1..2]]) appendFile :: FilePath -> String -> IO () -appendFile f txt = bracket (openFile f AppendMode) hClose - (\hdl -> hPutStr hdl txt) +appendFile f txt = withFile f AppendMode (\ hdl -> hPutStr hdl txt) -- | The 'readLn' function combines 'getLine' and 'readIO'. -- 1.7.10.4