Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- newtype ManagedT m a = ManagedT {
- runManagedT :: forall r. (a -> m r) -> m r
- allocate :: MonadBaseControl IO m => m a -> (a -> m b) -> ManagedT m a
- allocate_ :: MonadBaseControl IO m => m a -> m b -> ManagedT m ()
- lowerManagedT :: Monad m => ManagedT m a -> m a
- hoistManagedTReaderT :: Monad m => r -> ManagedT (ReaderT r m) a -> ManagedT m a
Documentation
This type is like a transformer version of the Managed
monad from the
managed
library. It can be used to manage resources by pairing together
their allocation with their finalizers.
The documentation for the managed
library is an excellent introduction to
the idea here.
We could use Codensity
directly, but we'd have to define an orphan instance
for MonadFix
. This also gives us the opportunity to give it a slightly more
friendly name.
We could also have used ResourceT
, but that would have involved writing
instances for MonadUnliftIO
. That could still be a good option to consider
later, however.
ManagedT | |
|
Instances
MonadTrans ManagedT Source # | |
Defined in Control.Monad.Trans.Managed | |
MonadReader s m => MonadState s (ManagedT m) Source # | |
MonadReader r m => MonadReader r (ManagedT m) Source # | |
Monad (ManagedT m) Source # | |
Functor (ManagedT m) Source # | |
MonadIO m => MonadFix (ManagedT m) Source # | We need this instance to tie the knot when initializing resources.
It'd be nice if we could do this with a We need to be careful not to leak allocated resources via the use of recursively-defined monadic actions when making use of this instance. |
Defined in Control.Monad.Trans.Managed | |
Applicative (ManagedT m) Source # | |
Defined in Control.Monad.Trans.Managed | |
MonadIO m => MonadIO (ManagedT m) Source # | |
Defined in Control.Monad.Trans.Managed |
allocate :: MonadBaseControl IO m => m a -> (a -> m b) -> ManagedT m a Source #
Allocate a resource by providing setup and finalizer actions.
allocate_ :: MonadBaseControl IO m => m a -> m b -> ManagedT m () Source #
Allocate a resource but do not return a reference to it.
lowerManagedT :: Monad m => ManagedT m a -> m a Source #
Run the provided computation by returning its result, and run any finalizers. Watch out: this function might leak finalized resources.