Safe Haskell | Safe-Inferred |
---|---|
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
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.