Copyright | (c) Michael Szvetits 2020 |
---|---|
License | BSD3 (see the file LICENSE) |
Maintainer | typedbyte@qualified.name |
Stability | stable |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
The resource effect allows a computation to allocate resources which are guaranteed to be released after their usage.
Synopsis
- class Monad m => Resource' tag m where
- bracket' :: m a -> (a -> m c) -> (a -> m b) -> m b
- bracketOnError' :: m a -> (a -> m c) -> (a -> m b) -> m b
- type Resource = Resource' G
- bracket :: Resource m => m a -> (a -> m c) -> (a -> m b) -> m b
- bracketOnError :: Resource m => m a -> (a -> m c) -> (a -> m b) -> m b
- finally' :: forall tag m a b. Resource' tag m => m a -> m b -> m a
- finally :: Resource m => m a -> m b -> m a
- onException' :: forall tag m a b. Resource' tag m => m a -> m b -> m a
- onException :: Resource m => m a -> m b -> m a
- data LowerIO m a
- runResourceIO' :: (Resource' tag `Via` LowerIO) m a -> m a
- runResourceIO :: (Resource `Via` LowerIO) m a -> m a
- tagResource' :: forall new m a. Via (Resource' G) (Tagger G new) m a -> m a
- retagResource' :: forall tag new m a. Via (Resource' tag) (Tagger tag new) m a -> m a
- untagResource' :: forall tag m a. Via (Resource' tag) (Tagger tag G) m a -> m a
Tagged Resource Effect
class Monad m => Resource' tag m where Source #
An effect that allows a computation to allocate resources which are guaranteed to be released after their usage.
:: m a | The computation which acquires the resource. |
-> (a -> m c) | The computation which releases the resource. |
-> (a -> m b) | The computation which uses the resource. |
-> m b | The result of the computation which used the resource. |
Acquire a resource, use it, and then release the resource after usage.
:: m a | The computation which acquires the resource. |
-> (a -> m c) | The computation which releases the resource. |
-> (a -> m b) | The computation which uses the resource. |
-> m b | The result of the computation which used the resource. |
Like bracket'
, but only performs the release computation if the usage
computation throws an exception.
Instances
MonadBaseControl IO m => Resource' (tag :: k) (LowerIO m) Source # | |
Control (Resource' tag) t m => Resource' (tag :: k) (Via eff t m) Source # | |
Handle (Resource' tag) t m => Resource' (tag :: k) (Via (Resource' tag) t m) Source # | |
Defined in Control.Effect.Resource bracket' :: Via (Resource' tag) t m a -> (a -> Via (Resource' tag) t m c) -> (a -> Via (Resource' tag) t m b) -> Via (Resource' tag) t m b Source # bracketOnError' :: Via (Resource' tag) t m a -> (a -> Via (Resource' tag) t m c) -> (a -> Via (Resource' tag) t m b) -> Via (Resource' tag) t m b Source # | |
Resource' new m => Resource' (tag :: k2) (Tagger tag new m) Source # | |
Untagged Resource Effect
If you don't require disambiguation of multiple resource effects (i.e., you only have one resource effect in your monadic context), it is recommended to always use the untagged resource effect.
bracketOnError :: Resource m => m a -> (a -> m c) -> (a -> m b) -> m b Source #
Convenience Functions
If you don't require disambiguation of multiple resource effects (i.e., you only have one resource effect in your monadic context), it is recommended to always use the untagged functions.
:: forall tag m a b. Resource' tag m | |
=> m a | The computation to run. |
-> m b | The computation to run afterwards, even if the first computation throws an exception. |
-> m a | The result of the first computation. |
A simpler version of bracket'
where one computation is guaranteed to
run after another.
:: forall tag m a b. Resource' tag m | |
=> m a | The computation to run. |
-> m b | The computation to run afterwards, only if the first computation throws an exception. |
-> m a | The result of the first computation. |
A simpler version of bracketOnError'
where one computation is guaranteed
to run after another in case the first computation throws an exception.
onException :: Resource m => m a -> m b -> m a Source #
The untagged version of onException'
.
Interpretations
The IO-based interpreter of the resource effect. This type implements the
Resource'
type class by using bracket
, thus requiring IO
at the bottom
of the monad transformer stack.
When interpreting the effect, you usually don't interact with this type directly, but instead use one of its corresponding interpretation functions.
Instances
MonadBaseControl IO m => Resource' (tag :: k) (LowerIO m) Source # | |
MonadBase b m => MonadBase b (LowerIO m) Source # | |
Defined in Control.Effect.Resource | |
MonadBaseControl b m => MonadBaseControl b (LowerIO m) Source # | |
MonadTrans (LowerIO :: (Type -> Type) -> Type -> Type) Source # | |
Defined in Control.Effect.Resource | |
MonadTransControl (LowerIO :: (Type -> Type) -> Type -> Type) Source # | |
Monad m => Monad (LowerIO m) Source # | |
Functor m => Functor (LowerIO m) Source # | |
Applicative m => Applicative (LowerIO m) Source # | |
MonadIO m => MonadIO (LowerIO m) Source # | |
Defined in Control.Effect.Resource | |
type StT (LowerIO :: (Type -> Type) -> Type -> Type) a Source # | |
type StM (LowerIO m) a Source # | |
Defined in Control.Effect.Resource |
runResourceIO' :: (Resource' tag `Via` LowerIO) m a -> m a Source #
Runs the resource effect using bracket
.
runResourceIO :: (Resource `Via` LowerIO) m a -> m a Source #
The untagged version of runResourceIO'
.
Tagging and Untagging
Conversion functions between the tagged and untagged resource effect, usually used in combination with type applications, like:
tagResource'
@"newTag" programretagResource'
@"oldTag" @"newTag" programuntagResource'
@"erasedTag" program