[Haskell-cafe] Re: Bulletproof resource management

Brandon Moore brandon_m_moore at yahoo.com
Fri Oct 8 22:07:13 EDT 2010



On Oct 8, 2010, at 2:18 PM, Florian Weimer <fw at deneb.enyo.de> wrote:

* Ben Franksen:

You might be interested in Lightweight Monadic Regions

 http://okmij.org/ftp/Haskell/regions.html#light-weight

which solve the problem (IMHO) in a much cleaner way, i.e. w/o explicit
closing and also w/o using finalizers.

Is this approach composeable in the sense that you can combine code
written in this code with code from another library?  I don't think
so.  The other library might provide something like IORef, and then
it's impossible to uphold static guarantees.

IMHO, this rules out such an approach (until it's part of the standard
library and forced upon everyone, which seems unlikely).

If you are worried about a handle being saved in the IORef to keep it outside the region, that's precisely what the library prevents. The typed handle itself can be carried outside the region, but the types make it impossible to perform any operations on it, so the resources can be released on exit from the region anyway. It's quite clever.


      


More information about the Haskell-Cafe mailing list