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 embed effect for integrating arbitrary monads into the effect system.
Synopsis
- class Monad m => Embed' tag n m | tag m -> n where
- embed' :: n a -> m a
- type Embed n = Embed' G n
- embed :: Embed n m => n a -> m a
- data Transformation n t m a
- runEmbed' :: forall tag n t m a. (forall b. n b -> t b) -> (Embed' tag n `Via` Transformation n t) m a -> m a
- runEmbed :: (forall b. n b -> t b) -> (Embed n `Via` Transformation n t) m a -> m a
- data Finalization m a
- runFinal' :: (Embed' tag m `Via` Finalization) m a -> m a
- runFinal :: (Embed m `Via` Finalization) m a -> m a
- tagEmbed' :: forall new n m a. (Embed' G n `Via` Tagger G new) m a -> m a
- retagEmbed' :: forall tag new n m a. (Embed' tag n `Via` Tagger tag new) m a -> m a
- untagEmbed' :: forall tag n m a. (Embed' tag n `Via` Tagger tag G) m a -> m a
Tagged Embed Effect
class Monad m => Embed' tag n m | tag m -> n where Source #
An effect that integrates a monad n
into the computation m
.
Since: 0.3.0.0
Instances
Embed' (tag :: k) Identity Identity Source # | |
Embed' (tag :: k) [] [] Source # | |
Defined in Control.Effect.Embed | |
Embed' (tag :: k) Maybe Maybe Source # | |
Embed' (tag :: k) IO IO Source # | |
Monad n => Embed' (tag :: k) n (Finalization n) Source # | |
Defined in Control.Effect.Embed embed' :: n a -> Finalization n a Source # | |
Handle '[Monad] (Embed' tag n) others t m => Embed' (tag :: k) n (EachVia (Embed' tag n ': others) t m) Source # | |
Find '[Monad] (Embed' tag n) other effs t m => Embed' (tag :: k) n (EachVia (other ': effs) t m) Source # | |
Defined in Control.Effect.Embed | |
Lift '[Monad] (Embed' tag n) t m => Embed' (tag :: k) n (EachVia ('[] :: [Effect]) t m) Source # | |
Defined in Control.Effect.Embed | |
Embed' tag t m => Embed' (tag :: k) n (Transformation n t m) Source # | |
Defined in Control.Effect.Embed embed' :: n a -> Transformation n t m a Source # | |
Embed' new n m => Embed' (tag :: k2) n (Tagger tag new m) Source # | |
Defined in Control.Effect.Embed |
Untagged Embed Effect
If you don't require disambiguation of multiple embed effects (i.e., you only have one embed effect in your monadic context), it is recommended to always use the untagged embed effect.
Interpretations
Via Transformation
data Transformation n t m a Source #
The transformation interpreter of the embed effect. This type implements the
Embed
type class by transforming the integrated monad n
into another
integrated monad t
via natural transformation.
When interpreting the effect, you usually don't interact with this type directly, but instead use one of its corresponding interpretation functions.
Instances
:: forall tag n t m a. (forall b. n b -> t b) | The natural transformation from monad |
-> (Embed' tag n `Via` Transformation n t) m a | The program whose embed effect should be handled. |
-> m a | The program with its embed effect handled. |
Runs the embed effect by transforming the integrated monad n
into another
integrated monad t
.
Since: 0.3.0.0
runEmbed :: (forall b. n b -> t b) -> (Embed n `Via` Transformation n t) m a -> m a Source #
The untagged version of runEmbed'
.
Via Finalization
data Finalization m a Source #
The finalization interpreter of the embed effect. This type implements the
Embed
type class by declaring the integrated monad the final monad m
(also called the "base monad").
Chances are very high that you only need this interpreter if you have a
custom final monad because the Embed'
effect is already implemented for
final monads like IO
, Maybe
, []
and Identity
.
When interpreting the effect, you usually don't interact with this type directly, but instead use one of its corresponding interpretation functions.
Since: 0.3.0.0
Instances
:: (Embed' tag m `Via` Finalization) m a | The program whose embed effect should be handled. |
-> m a | The program with its embed effect handled. |
Runs the embed effect by declaring the integrated monad the final monad.
Since: 0.3.0.0
runFinal :: (Embed m `Via` Finalization) m a -> m a Source #
The untagged version of runFinal'
.
Since: 0.3.0.0
Tagging and Untagging
Conversion functions between the tagged and untagged embed effect, usually used in combination with type applications, like:
tagEmbed'
@"newTag" programretagEmbed'
@"oldTag" @"newTag" programuntagEmbed'
@"erasedTag" program