Safe Haskell | None |
---|---|
Language | Haskell2010 |
An effect allowing writes to an accumulated quantity alongside a computed value. A Writer
w
effect keeps track of a monoidal datum of type w
and strictly appends to that monoidal value with the tell
effect. Writes to that value can be detected and intercepted with the listen
and censor
effects.
Predefined carriers:
- Control.Carrier.Writer.Strict. (A lazy carrier is not provided due to the inherent space leaks associated with lazy writer monads.)
- Control.Monad.Trans.RWS.Lazy
- Control.Monad.Trans.RWS.Strict
- Control.Monad.Trans.Writer.Lazy
- Control.Monad.Trans.Writer.Strict
- If
Writer
w
is the last effect in a stack, it can be interpreted to a tuple(w, a)
given some result typea
and the presence of aMonoid
instance forw
.
Since: 0.1.0.0
Synopsis
- data Writer w m k
- tell :: Has (Writer w) sig m => w -> m ()
- listen :: Has (Writer w) sig m => m a -> m (w, a)
- listens :: Has (Writer w) sig m => (w -> b) -> m a -> m (b, a)
- censor :: Has (Writer w) sig m => (w -> w) -> m a -> m a
- class (HFunctor sig, Monad m) => Algebra sig m | m -> sig
- type Has eff sig m = (Members eff sig, Algebra sig m)
- run :: Identity a -> a
Writer effect
Since: 0.1.0.0
Instances
Effect (Writer w) Source # | |
HFunctor (Writer w) Source # | |
Monoid w => Algebra (Writer w) ((,) w) Source # | |
Functor m => Functor (Writer w m) Source # | |
(Algebra sig m, Effect sig, Monoid w) => Algebra (Writer w :+: sig) (WriterT w m) Source # | |
(Algebra sig m, Effect sig, Monoid w) => Algebra (Writer w :+: sig) (WriterT w m) Source # | |
(Monoid w, Algebra sig m, Effect sig) => Algebra (Writer w :+: sig) (WriterC w m) Source # | |
(Algebra sig m, Effect sig, Monoid w) => Algebra (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) Source # | |
(Algebra sig m, Effect sig, Monoid w) => Algebra (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) Source # | |
Re-exports
class (HFunctor sig, Monad m) => Algebra sig m | m -> sig Source #
The class of carriers (results) for algebras (effect handlers) over signatures (effects), whose actions are given by the alg
method.
Since: 1.0.0.0
Instances
type Has eff sig m = (Members eff sig, Algebra sig m) Source #
m
is a carrier for sig
containing eff
.
Note that if eff
is a sum, it will be decomposed into multiple Member
constraints. While this technically allows one to combine multiple unrelated effects into a single Has
constraint, doing so has two significant drawbacks:
- Due to a problem with recursive type families, this can lead to significantly slower compiles.
- It defeats
ghc
’s warnings for redundant constraints, and thus can lead to a proliferation of redundant constraints as code is changed.