[Haskell-cafe] Exception safe resource management with dynamic regions, call for review

Yuras Shumovich shumovichy at gmail.com
Sat Feb 14 21:36:09 UTC 2015


I'm asking for code and design review for `io-region` library. It is
already on Hackage for convenience and easy access to haddock:

Manual exception handling in Haskell almost never is a good idea, except
probably trivial cases where `bracket` is enough. A number of special
libraries where created to help with exception handling. `io-regions` is
one of them.

Initially it was an attempt to solve the double-throw issue, but I found
it unsolvable in library without changes in language itself. So now it
is an attempt to design easy to use API with a bit different set of

The library is based on idea of regions that own resources. The
resources are released when the region is closed. Early releasing and
ownership transferring are supported. Types are *not* used to prevent
use-after-free errors.

The API is not monadic, and it is the biggest difference from other
libraries. Regions are first-class citizens, so you can manipulate them,
pass as arguments to functions, send to other thread, store in data
types. Such flexibility has its cost -- a bit more manual management.

The implementation is based on STM and is thread safe, that allows e.g.
atomic ownership transferring between threads.

The nearest competitor I think is `resourset` package, and I still
recommend it by default. Though I convinced myself that `io-region` is
good enough, and I'm using it in productions (for two weeks already :) )


More information about the Haskell-Cafe mailing list