On Thu, Oct 18, 2007 at 01:16:37PM +0100, Magnus Therning wrote:
> On Thu, Oct 18, 2007 at 20:58:45 +1000, Matthew Brecknell wrote:
> >For a less hackish solution, you need to do a bit more work. Again, this
> >is untested.
> >
> >> loadAndCheck fn = bracket (openFile fn ReadMode) hClose checkContents
> >> checkContents fh = do { s <- hGetContents fh; return $! hasEmpty s }
> >
> >Note the explicit close, and "return $!" to ensure that hasEmpty has
> >done its work before the file is closed.
> 
> Ah, `bracket` is a handy function to know!

Note that you almost never want to use the bracket defined in Haskell98,
nor the one in IO.Error.  You want the bracket defined in
Control.Exception.
-- 
David Roundy
Department of Physics
Oregon State University

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to