Re: [Haskell-cafe] Bulletproof resource management

From: Florian Weimer
* Henning Thielemann:
Some open/close pairs have corresponding 'with' functions, that are implemented using Exception.bracket. You can also use them within GHCi. I think using both manual resource deallocation and finalizers makes everything more complicated and more unreliable.
It seems that Exception.bracket does not work in all cases, see the recent "MonadCatchIO, finally and the error monad" thread.
Anyway, the ability of closures (and threads) means that something like Exception.bracket does not prevent access to closed handles, so I still need an additional safety net.
Enumeration-based interfaces will prevent access to closed handles[1], [2], etc. You can use this style for more than just handles and sockets, e.g. Takusen uses it for database connections. I think somebody else already mentioned region-based management, which is also completely safe AFAIK. [1] http://hackage.haskell.org/package/iteratee [2] http://hackage.haskell.org/package/enumerator

I think somebody else already mentioned region-based management, which is also completely safe AFAIK.
Ben Franksen mentioned my brother's regions package [1]. He's about to release a new version with simpler type machinery. The list of packages that make use of the regions package [2] can serve as an example how to use these lightweight monadic regions [3]. Regards, Roel 1 - http://hackage.haskell.org/package/regions 2 - http://bifunctor.homelinux.net/~roel/cgi-bin/hackage-scripts/revdeps/regions... 3 - http://okmij.org/ftp/Haskell/regions.html#light-weight
participants (2)
-
John Lato
-
Roel van Dijk