Re: File remains locked after crash
"Neil Mitchell" <[email protected]> Mon, 1 May 2006 17:18:46 +0100
| Newsgroups | gmane.comp.lang.haskell.hugs.bugs |
|---|---|
| Message-ID | <[email protected]> |
Hi, > This should be a better implementation of writeFile: > > import Control.Exception > import System.IO > > writeFile' :: FilePath -> String -> IO () > writeFile' f txt = bracket (openFile f WriteMode) hClose > (flip hPutStr txt) Yes, it works better in the error case, so is definately preferable. Is there any reason why this isn't the standard definition of writeFile? Especially in an interactive environment likes Hugs/GHCi. The problem still remains however with the following command: writeFile' "test4.txt" (show $ last [1..]) Which is non-terminating therefore requires the user to break the program with Ctrl-C. When the user presses Ctrl-C the bracket is not run, so the file remains locked afterwards. Thanks Neil