Copyright | (c) 2023 Sayo Koyoneda |
---|---|
License | MPL-2.0 (see the file LICENSE) |
Maintainer | [email protected] |
Safe Haskell | None |
Language | GHC2021 |
Data.Effect.Writer
Description
Effects that can accumulate values monoidally in a context.
Synopsis
- data Tell w a where
- data WriterH w (f :: Type -> Type) a where
- type LTell w = LiftFOE (Tell w)
- pattern LTell :: forall a w f. () => (a ~ (), ()) => w -> LiftFOE (Tell w) f a
- tell :: SendFOE (Tell w) f => w -> f ()
- tell' :: forall {k} (tag :: k) w f. SendFOE (Tag (Tell w) tag) f => w -> f ()
- tell'' :: forall {k} (key :: k) w f. SendFOEBy key (Tell w) f => w -> f ()
- listen :: forall a w f. SendHOE (WriterH w) f => f a -> f (w, a)
- listen' :: forall {k} (tag :: k) a w f. SendHOE (TagH (WriterH w) tag) f => f a -> f (w, a)
- listen'' :: forall {k} (key :: k) a w f. SendHOEBy key (WriterH w) f => f a -> f (w, a)
- censor :: forall w a f. SendHOE (WriterH w) f => (w -> w) -> f a -> f a
- censor' :: forall {k} (tag :: k) w a f. SendHOE (TagH (WriterH w) tag) f => (w -> w) -> f a -> f a
- censor'' :: forall {k} (key :: k) w a f. SendHOEBy key (WriterH w) f => (w -> w) -> f a -> f a
- pass :: (Tell w <: m, WriterH w <<: m, Monad m) => m (w -> w, a) -> m a
Documentation
An effect that can accumulate values monoidally in a context.
data WriterH w (f :: Type -> Type) a where Source #
An effect that performs local operations on accumulations in the context on a per-scope basis.
tell :: SendFOE (Tell w) f => w -> f () Source #
Accumulates new values to the cumulative value held in the context.
tell' :: forall {k} (tag :: k) w f. SendFOE (Tag (Tell w) tag) f => w -> f () Source #
Accumulates new values to the cumulative value held in the context.
tell'' :: forall {k} (key :: k) w f. SendFOEBy key (Tell w) f => w -> f () Source #
Accumulates new values to the cumulative value held in the context.
Arguments
:: forall a w f. SendHOE (WriterH w) f | |
=> f a | The scope from which to obtain the accumulation. |
-> f (w, a) |
Obtains the accumulated value in the scope and returns it together as a pair.
Arguments
:: forall {k} (tag :: k) a w f. SendHOE (TagH (WriterH w) tag) f | |
=> f a | The scope from which to obtain the accumulation. |
-> f (w, a) |
Obtains the accumulated value in the scope and returns it together as a pair.
Arguments
:: forall {k} (key :: k) a w f. SendHOEBy key (WriterH w) f | |
=> f a | The scope from which to obtain the accumulation. |
-> f (w, a) |
Obtains the accumulated value in the scope and returns it together as a pair.
Arguments
:: forall w a f. SendHOE (WriterH w) f | |
=> (w -> w) | |
-> f a | The scope where the modification is applied. |
-> f a |
Modifies the accumulation in the scope based on the given function.
Arguments
:: forall {k} (tag :: k) w a f. SendHOE (TagH (WriterH w) tag) f | |
=> (w -> w) | |
-> f a | The scope where the modification is applied. |
-> f a |
Modifies the accumulation in the scope based on the given function.
Arguments
:: forall {k} (key :: k) w a f. SendHOEBy key (WriterH w) f | |
=> (w -> w) | |
-> f a | The scope where the modification is applied. |
-> f a |
Modifies the accumulation in the scope based on the given function.
pass :: (Tell w <: m, WriterH w <<: m, Monad m) => m (w -> w, a) -> m a Source #
For a given scope, uses the function (the first component of the pair returned by that scope) to modify the accumulated value of that scope, and then accumulates the result into the current outer scope.
pass m = do (w, (f, a)) <- listen m tell $ f w pure a