
11 Oct
2010
11 Oct
'10
5:14 a.m.
It is, BTW, always preferable to use withFile over openFile, if you can. This makes your code cleaner and also exception-safe.
Hi Ertugrul, I don't think I quite understand. How is withFile exception-safe? Under the covers it's using openFile. I was under the impression withFile was just a nice way to remove boilerplate file operation code. Here's what I found on hoogle: "withFile http://haskell.org/hoogle/?hoogle=withFile name mode act opens a file using openFile http://haskell.org/hoogle/?hoogle=openFile and passes the resulting handle to the computation act. The handle will be closed on exit from withFile http://haskell.org/hoogle/?hoogle=withFile, whether by normal termination or by raising an exception." Thanks, Jimmy