IOR-0.1: Region based resource management for the IO monad.

Stabilityexperimental
Maintainertomac `at` pacific `dot` net `dot` au

System.IOR

Contents

Description

Region based resource management for the IO monad. Based on the ideas and code from http://okmij.org/ftp/Haskell/regions.html

Synopsis

Type Classes and Auxiliary Data Types

class RElem r rs Source

Instances

RElem r rs => RElem r (RCons r' rs) 
RElem r (RCons r rs) 

data RCons r rs Source

Instances

RElem r rs => RElem r (RCons r' rs) 
RElem r (RCons r rs) 

IOR Monad

data IOR r rs a Source

IO monad with support for region based resource allocation. A computation of type IOR r rs a wraps an action of type IO a where r is an unconstrained type variable indicating the current region and rs is a collection of all accessible regions within the computation.

IO actions can be lifted into the IOR monad using liftIO. It is safe to throw IOError-s inside an IOR computation. Allocated resources will be released on exit automatically.

Instances

Typeable3 IOR 
MonadError IOError (IOR r rs) 
Monad (IOR r rs) 
Functor (IOR r rs) 
MonadFix (IOR r rs) 
Applicative (IOR r rs) 
MonadIO (IOR r rs) 
(Data r, Data rs, Data a) => Data (IOR r rs a) 

runIOR :: IOR r (RCons r RNil) a -> IO aSource

Create the initial region, r, and run the computation returning a value of type IO a.

newIOR :: IOR r' (RCons r' rs) a -> IOR r rs aSource

Create a new region r' inside r. All resources allocated in r' are only accessible from r' and any of it's child regions. On exit from the region, all allocated resources are automatically released.

Region Tags

data IORTag r Source

A region tag IORTag r captures state of the region r including all currently allocated resources in r.

Instances

getIORTag :: IOR r rs (IORTag r)Source

Get the current region's tag.

withIORTag :: RElem r' rs => IORTag r' -> IOR r' rs a -> IOR r rs aSource

Temporarily change the current region from r to r'. This allows allocation of resources in r'.

r' has to be one of the parent regions of r.