Safe Haskell | None |
---|
- newtype ExceptionT m a = ExceptionT {
- runExceptionT :: m (Either SomeException a)
- data InvalidAccess = InvalidAccess {}
- class (MonadThrow m, MonadUnsafeIO m, MonadIO m, Applicative m) => MonadResource m where
- liftResourceT :: ResourceT IO a -> m a
- class Monad m => MonadThrow m where
- monadThrow :: Exception e => e -> m a
- class Monad m => MonadUnsafeIO m where
- unsafeLiftIO :: IO a -> m a
- data ReleaseKey = ReleaseKey !(IORef ReleaseMap) !Int
- data ReleaseMap
- = ReleaseMap !NextKey !RefCount !(IntMap (IO ()))
- | ReleaseMapClosed
- type ResIO a = ResourceT IO a
- newtype ResourceT m a = ResourceT {
- unResourceT :: IORef ReleaseMap -> m a
- stateAlloc :: IORef ReleaseMap -> IO ()
- stateCleanup :: IORef ReleaseMap -> IO ()
- transResourceT :: (m a -> n b) -> ResourceT m a -> ResourceT n b
- newtype Resource a = Resource ((forall b. IO b -> IO b) -> IO (Allocated a))
- data Allocated a = Allocated !a !(IO ())
- with :: MonadBaseControl IO m => Resource a -> (a -> m b) -> m b
- mkResource :: IO a -> (a -> IO ()) -> Resource a
Documentation
newtype ExceptionT m a Source
The express purpose of this transformer is to allow non-IO
-based monad
stacks to catch exceptions via the MonadThrow
typeclass.
Since 0.3.0
ExceptionT | |
|
MonadTrans ExceptionT | |
MonadTransControl ExceptionT | |
MonadRWS r w s m => MonadRWS r w s (ExceptionT m) | |
MonadBase b m => MonadBase b (ExceptionT m) | |
MonadBaseControl b m => MonadBaseControl b (ExceptionT m) | |
MonadError e m => MonadError e (ExceptionT m) | |
MonadReader r m => MonadReader r (ExceptionT m) | |
MonadState s m => MonadState s (ExceptionT m) | |
MonadWriter w m => MonadWriter w (ExceptionT m) | |
Monad m => Monad (ExceptionT m) | |
Monad m => Functor (ExceptionT m) | |
Monad m => Applicative (ExceptionT m) | |
MonadIO m => MonadIO (ExceptionT m) | |
MonadCont m => MonadCont (ExceptionT m) | |
Monad m => MonadThrow (ExceptionT m) | |
MonadResource m => MonadResource (ExceptionT m) |
data InvalidAccess Source
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
class (MonadThrow m, MonadUnsafeIO m, MonadIO m, Applicative m) => MonadResource m whereSource
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
liftResourceT :: ResourceT IO a -> m aSource
Lift a ResourceT IO
action into the current Monad
.
Since 0.4.0
MonadResource m => MonadResource (ListT m) | |
MonadResource m => MonadResource (MaybeT m) | |
MonadResource m => MonadResource (IdentityT m) | |
MonadResource m => MonadResource (ExceptionT m) | |
(MonadThrow m, MonadUnsafeIO m, MonadIO m, Applicative m) => MonadResource (ResourceT m) | |
MonadResource m => MonadResource (ContT r m) | |
(Error e, MonadResource m) => MonadResource (ErrorT e m) | |
MonadResource m => MonadResource (ReaderT r m) | |
MonadResource m => MonadResource (StateT s m) | |
MonadResource m => MonadResource (StateT s 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) |
class Monad m => MonadThrow m whereSource
A Monad
which can throw exceptions. Note that this does not work in a
vanilla ST
or Identity
monad. Instead, you should use the ExceptionT
transformer in your stack if you are dealing with a non-IO
base monad.
Since 0.3.0
monadThrow :: Exception e => e -> m aSource
MonadThrow [] | |
MonadThrow IO | |
MonadThrow Maybe | |
MonadThrow (Either SomeException) | |
MonadThrow m => MonadThrow (ListT m) | |
MonadThrow m => MonadThrow (MaybeT m) | |
MonadThrow m => MonadThrow (IdentityT m) | |
Monad m => MonadThrow (ExceptionT m) | |
MonadThrow m => MonadThrow (ResourceT m) | |
MonadThrow m => MonadThrow (ContT r m) | |
(Error e, MonadThrow m) => MonadThrow (ErrorT e m) | |
MonadThrow m => MonadThrow (ReaderT r m) | |
MonadThrow m => MonadThrow (StateT s m) | |
MonadThrow m => MonadThrow (StateT s m) | |
(Monoid w, MonadThrow m) => MonadThrow (WriterT w m) | |
(Monoid w, MonadThrow m) => MonadThrow (WriterT w m) | |
(Monoid w, MonadThrow m) => MonadThrow (RWST r w s m) | |
(Monoid w, MonadThrow m) => MonadThrow (RWST r w s m) |
class Monad m => MonadUnsafeIO m whereSource
A Monad
based on some monad which allows running of some IO
actions,
via unsafe calls. This applies to IO
and ST
, for instance.
Since 0.3.0
unsafeLiftIO :: IO a -> m aSource
MonadUnsafeIO IO | |
(MonadTrans t, MonadUnsafeIO m, Monad (t m)) => MonadUnsafeIO (t m) | |
MonadUnsafeIO (ST s) | |
MonadUnsafeIO (ST s) |
data ReleaseKey Source
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
ReleaseKey !(IORef ReleaseMap) !Int |
data ReleaseMap Source
ReleaseMap !NextKey !RefCount !(IntMap (IO ())) | |
ReleaseMapClosed |
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
ResourceT | |
|
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) | |
Typeable1 m => Typeable1 (ResourceT m) | |
Applicative m => Applicative (ResourceT m) | |
MonadIO m => MonadIO (ResourceT m) | |
MonadCont m => MonadCont (ResourceT m) | |
MonadThrow m => MonadThrow (ResourceT m) | |
(MonadThrow m, MonadUnsafeIO m, MonadIO m, Applicative m) => MonadResource (ResourceT m) | |
(MonadIO m, MonadActive m) => MonadActive (ResourceT m) |
stateAlloc :: IORef ReleaseMap -> IO ()Source
stateCleanup :: IORef ReleaseMap -> IO ()Source
transResourceT :: (m a -> n b) -> ResourceT m a -> ResourceT n bSource
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
A method for allocating a scarce resource, providing the means of freeing
it when no longer needed. This data type provides
Functor
@Applicative@Monad
instances for composing different resources
together. You can allocate these resources using either the bracket
pattern (via with
) or using ResourceT
(via allocateResource
).
This concept was originally introduced by Gabriel Gonzalez and described at: http://www.haskellforall.com/2013/06/the-resource-applicative.html. The implementation in this package is slightly different, due to taking a different approach to async exception safety.
Since 0.4.10
with :: MonadBaseControl IO m => Resource a -> (a -> m b) -> m bSource
Allocate the given resource and provide it to the provided function. The
resource will be freed as soon as the inner block is exited, whether
normally or via an exception. This function is similar in function to
bracket
.
Since 0.4.10
Create a Resource
value using the given allocate and free functions.
Since 0.4.10