The regions package

This package provides the region monad transformer. Scarce resources like
files, memory pointers or USB devices for example can be opened in a
region. When the region terminates, all opened resources will be automatically
closed. The main advantage of regions is that the opened resources can not be
returned from the region which ensures no I/O with closed resources is
possible.

The primary technique used in this package is called "Lightweight monadic
regions" which was invented by Oleg Kiselyov and Chung-chieh Shan. See: