use bracket in appendFile (like writeFile)
authorRoss Paterson <ross@soi.city.ac.uk>
Thu, 4 May 2006 09:15:28 +0000 (09:15 +0000)
committerRoss Paterson <ross@soi.city.ac.uk>
Thu, 4 May 2006 09:15:28 +0000 (09:15 +0000)
System/IO.hs

index 201bb22..8982119 100644 (file)
@@ -308,10 +308,8 @@ 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 name str = do
-    hdl <- openFile name AppendMode
-    hPutStr hdl str
-    hClose hdl
+appendFile f txt = bracket (openFile f AppendMode) hClose
+                          (\hdl -> hPutStr hdl txt)
 
 -- | The 'readLn' function combines 'getLine' and 'readIO'.