[Haskell-cafe] Re: Re: Bulletproof resource management

Ben Franksen ben.franksen at online.de
Fri Oct 8 16:11:03 EDT 2010

Florian Weimer 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.

I see no reason why not.

> The other library might provide something like IORef, and then
> it's impossible to uphold static guarantees.

The way it is implemented for instance in the regions package, you can lift
IO actions into the Region monad, as there are

  instance MonadCatchIO pr => MonadCatchIO (RegionT s pr)   
  instance MonadIO pr => MonadIO (RegionT s pr)

Or maybe I don't understand your objection?

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

I don't think it is necessary or even desirable to enforce this, or any
other style of programming, especially not by standard library design.


More information about the Haskell-Cafe mailing list