Control.Monad.Trans.Resource.Internal

resourcet-1.1.7: Deterministic allocation and freeing of scarce resources.

Safe Haskell | Safe
Language | Haskell98

Control.Monad.Trans.Resource.Internal

Synopsis

- data InvalidAccess = InvalidAccess {
  - functionName :: String
  }
- class (MonadThrow m, MonadIO m, Applicative m, MonadBase IO m) => MonadResource m where
  - liftResourceT :: ResourceT IO a -> m a
- data ReleaseKey = ReleaseKey !(IORef ReleaseMap) !Int
- data ReleaseMap
  - = ReleaseMap !NextKey !RefCount !(IntMap (ReleaseType -> IO ()))
  - | ReleaseMapClosed
- type ResIO a = ResourceT IO a
- newtype ResourceT m a = ResourceT {
  - unResourceT :: IORef ReleaseMap -> m a
  }
- stateAlloc :: IORef ReleaseMap -> IO ()
- stateCleanup :: ReleaseType -> IORef ReleaseMap -> IO ()
- transResourceT :: (m a -> n b) -> ResourceT m a -> ResourceT n b
- register' :: IORef ReleaseMap -> IO () -> IO ReleaseKey
- registerType :: IORef ReleaseMap -> (ReleaseType -> IO ()) -> IO ReleaseKey

# Documentation

data InvalidAccess

Indicates either an error in the library, or misuse of it (e.g., a `ResourceT`'s state is accessed after being released).

Since 0.3.0

Constructors

InvalidAccess |
Fields functionName :: String

Instances

Show InvalidAccess |
Exception InvalidAccess |

class (MonadThrow m, MonadIO m, Applicative m, MonadBase IO m) => MonadResource m where

A `Monad` which allows for safe resource allocation. In theory, any monad transformer stack included a `ResourceT` can be an instance of `MonadResource`.

Note: `runResourceT` has a requirement for a `MonadBaseControl IO m` monad, which allows control operations to be lifted. A `MonadResource` does not have this requirement. This means that transformers such as `ContT` can be an instance of `MonadResource`. However, the `ContT` wrapper will need to be unwrapped before calling `runResourceT`.

Since 0.3.0

Methods

liftResourceT :: ResourceT IO a -> m a

Lift a `ResourceT IO` action into the current `Monad`.

Since 0.4.0

Instances

MonadResource m => MonadResource (ListT m) |
MonadResource m => MonadResource (MaybeT m) |
MonadResource m => MonadResource (IdentityT m) |
(MonadThrow m, MonadBase IO m, MonadIO m, Applicative m) => MonadResource (ResourceT m) |
MonadResource m => MonadResource (ContT r m) |
MonadResource m => MonadResource (ReaderT r m) |
MonadResource m => MonadResource (StateT s m) |
MonadResource m => MonadResource (StateT s m) |
MonadResource m => MonadResource (ExceptT e m) |
(Error e, MonadResource m) => MonadResource (ErrorT e m) |
(Monoid w, MonadResource m) => MonadResource (WriterT w m) |
(Monoid w, MonadResource m) => MonadResource (WriterT w m) |
(Monoid w, MonadResource m) => MonadResource (RWST r w s m) |
(Monoid w, MonadResource m) => MonadResource (RWST r w s m) |

data ReleaseKey

A lookup key for a specific release action. This value is returned by `register` and `allocate`, and is passed to `release`.

Since 0.3.0

Constructors

ReleaseKey !(IORef ReleaseMap) !Int |

data ReleaseMap

Constructors

ReleaseMap !NextKey !RefCount !(IntMap (ReleaseType -> IO ())) |
ReleaseMapClosed |

type ResIO a = ResourceT IO a

Convenient alias for `ResourceT IO`.

newtype ResourceT m a

The Resource transformer. This transformer keeps track of all registered actions, and calls them upon exit (via `runResourceT`). Actions may be registered via `register`, or resources may be allocated atomically via `allocate`. `allocate` corresponds closely to `bracket`.

Releasing may be performed before exit via the `release` function. This is a highly recommended optimization, as it will ensure that scarce resources are freed early. Note that calling `release` will deregister the action, so that a release action will only ever be called once.

Since 0.3.0

Constructors

ResourceT |
Fields unResourceT :: IORef ReleaseMap -> m a

Instances

MFunctor ResourceT | Since 0.4.7
MMonad ResourceT | Since 0.4.7
MonadTrans ResourceT |
MonadTransControl ResourceT |
MonadRWS r w s m => MonadRWS r w s (ResourceT m) |
MonadBase b m => MonadBase b (ResourceT m) |
MonadBaseControl b m => MonadBaseControl b (ResourceT m) |
MonadError e m => MonadError e (ResourceT m) |
MonadReader r m => MonadReader r (ResourceT m) |
MonadState s m => MonadState s (ResourceT m) |
MonadWriter w m => MonadWriter w (ResourceT m) |
Monad m => Monad (ResourceT m) |
Functor m => Functor (ResourceT m) |
Applicative m => Applicative (ResourceT m) |
Alternative m => Alternative (ResourceT m) | Since 1.1.5
MonadPlus m => MonadPlus (ResourceT m) | Since 1.1.5
MonadThrow m => MonadThrow (ResourceT m) |
MonadCatch m => MonadCatch (ResourceT m) |
MonadMask m => MonadMask (ResourceT m) |
MonadIO m => MonadIO (ResourceT m) |
MonadCont m => MonadCont (ResourceT m) |
(MonadThrow m, MonadBase IO m, MonadIO m, Applicative m) => MonadResource (ResourceT m) |
type StT ResourceT a = a |
type StM (ResourceT m) a = StM m a |

stateAlloc :: IORef ReleaseMap -> IO ()

stateCleanup :: ReleaseType -> IORef ReleaseMap -> IO ()

transResourceT :: (m a -> n b) -> ResourceT m a -> ResourceT n b

Transform the monad a `ResourceT` lives in. This is most often used to strip or add new transformers to a stack, e.g. to run a `ReaderT`.

Note that this function is a slight generalization of `hoist`.

Since 0.3.0

register' :: IORef ReleaseMap -> IO () -> IO ReleaseKey

registerType :: IORef ReleaseMap -> (ReleaseType -> IO ()) -> IO ReleaseKey

Since 1.1.2