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
_______________________________________________
Hugs-Bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/hugs-bugs

Reply via email to