On Thu, Oct 18, 2007 at 09:25:32 -0400, David Roundy wrote:
>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.Yes, thankfully that's documented in the Haddock for the only one that turns up on Hoogle. /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus.therning@gmail.com http://therning.org/magnus
pgpS5kB9LvJaR.pgp
Description: PGP signature
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
