-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Region based resource management for the IO monad. -- -- IOR monad is a wrapper around IO that allows region based resource -- management. @package IOR @version 0.1 -- | Resource management in the IOR monad. module System.IOR.Resource -- | Resource r a wraps a resource of type a so it -- can be managed inside region r and automatically released -- upon exit from r. data Resource r a -- | Extract a from the Resource wrapper. getResource :: Resource r a -> a -- | manage a f will create a new Resource wrapper -- around the value of type a in region r, given a -- finalizer f. Each finalizer is guaranteed to automatically be -- called upon exit from the region. Finalizers are called in the last -- in, first out fashion. So the finalizer of the very last resource -- allocated will be the first to get called. -- -- Note that finalizers must not throw any errors. Failing to ensure that -- all errors in a finalizer are handled may result in a resource leak. manage :: a -> (a -> IO ()) -> IOR r rs (Resource r a) -- | release res is used to force the resource res -- to be released immediately. Finalizer for res will be called -- and removed from the stack of finalizers in region r'. release :: (RElem r' rs) => Resource r' a -> IOR r rs () -- | Region based resource management for the IO monad. Based on the ideas -- and code from http://okmij.org/ftp/Haskell/regions.html module System.IOR class RElem r rs data RCons r rs data RNil -- | 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. data IOR r rs a -- | Create the initial region, r, and run the computation -- returning a value of type IO a. runIOR :: IOR r (RCons r RNil) a -> IO a -- | 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. newIOR :: IOR r' (RCons r' rs) a -> IOR r rs a -- | A region tag IORTag r captures state of the region -- r including all currently allocated resources in r. data IORTag r -- | Get the current region's tag. getIORTag :: IOR r rs (IORTag r) -- | 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. withIORTag :: (RElem r' rs) => IORTag r' -> IOR r' rs a -> IOR r rs a -- | Mutable references in the IOR monad. module Data.IORRef -- | A value of type IORRef r a is a mutable variable in -- region r, containing a value of type a. data IORRef r a -- | Create a new IORRef in region r. newIORRef :: a -> IOR r rs (IORRef r a) -- | Read the value of an IORRef. readIORRef :: (RElem r' rs) => IORRef r' a -> IOR r rs a -- | Write a new value into an IORRef. writeIORRef :: (RElem r' rs) => IORRef r' a -> a -> IOR r rs () -- | Mutate the contents of an IORRef. modifyIORRef :: (RElem r' rs) => IORRef r' a -> (a -> a) -> IOR r rs () instance Typeable2 IORRef instance (Data r, Data a) => Data (IORRef r a) instance Eq (IORRef r a)