regions-0.8: Provides the region monad for safely opening and working with scarce resources.

MaintainerBas van Dijk <>



This module is not intended for end-users. It should only be used by library authors wishing to extend this regions library.



type Finalizer = IO ()Source

An IO computation that closes or finalizes a resource. For example hClose or free.

data FinalizerHandle r Source

A handle to a Finalizer that allows you to duplicate it to a parent region using dup.

Duplicating a finalizer means that instead of it being performed when the current region terminates it is performed when the parent region terminates.


onExit :: MonadIO pr => Finalizer -> RegionT s pr (FinalizerHandle (RegionT s pr))Source

Register the Finalizer in the region. When the region terminates all registered finalizers will be perfomed if they're not duplicated to a parent region.

Note that finalizers are run in LIFO order (Last In First Out). So executing the following:

runRegionT $ do
  _ <- onExit $ putStrLn "finalizer 1"
  _ <- onExit $ putStrLn "finalizer 2"
  return ()


finalizer 2
finalizer 1