Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Writer w m k
- tell :: (Member (Writer w) sig, Carrier sig m) => w -> m ()
- listen :: (Member (Writer w) sig, Carrier sig m) => m a -> m (w, a)
- listens :: (Member (Writer w) sig, Carrier sig m) => (w -> b) -> m a -> m (b, a)
- censor :: (Member (Writer w) sig, Carrier sig m) => (w -> w) -> m a -> m a
- runWriter :: forall w sig m a. (Carrier sig m, Effect sig, Monad m, Monoid w) => Eff (WriterC w m) a -> m (w, a)
- execWriter :: forall w sig m a. (Carrier sig m, Effect sig, Monad m, Monoid w) => Eff (WriterC w m) a -> m w
- newtype WriterC w m a = WriterC {
- runWriterC :: w -> m (w, a)
Documentation
tell :: (Member (Writer w) sig, Carrier sig m) => w -> m () Source #
Write a value to the log.
fst (run (runWriter (mapM_ (tell . Sum) (0 : ws)))) == foldMap Sum ws
listen :: (Member (Writer w) sig, Carrier sig m) => m a -> m (w, a) Source #
Run a computation, returning the pair of its output and its result.
run (runWriter (fst <$ tell (Sum a) <*> listen @(Sum Integer) (tell (Sum b)))) == (Sum a <> Sum b, Sum b)
listens :: (Member (Writer w) sig, Carrier sig m) => (w -> b) -> m a -> m (b, a) Source #
Run a computation, applying a function to its output and returning the pair of the modified output and its result.
run (runWriter (fst <$ tell (Sum a) <*> listens @(Sum Integer) (applyFun f) (tell (Sum b)))) == (Sum a <> Sum b, applyFun f (Sum b))
censor :: (Member (Writer w) sig, Carrier sig m) => (w -> w) -> m a -> m a Source #
Run a computation, modifying its output with the passed function.
run (execWriter (censor (applyFun f) (tell (Sum a)))) == applyFun f (Sum a)
run (execWriter (tell (Sum a) *> censor (applyFun f) (tell (Sum b)) *> tell (Sum c))) == (Sum a <> applyFun f (Sum b) <> Sum c)
runWriter :: forall w sig m a. (Carrier sig m, Effect sig, Monad m, Monoid w) => Eff (WriterC w m) a -> m (w, a) Source #
execWriter :: forall w sig m a. (Carrier sig m, Effect sig, Monad m, Monoid w) => Eff (WriterC w m) a -> m w Source #
newtype WriterC w m a Source #
A space-efficient carrier for Writer
effects.
This is based on a post Gabriel Gonzalez made to the Haskell mailing list: https://mail.haskell.org/pipermail/libraries/2013-March/019528.html
Note that currently, the constant-space behaviour observed there only occurs when using WriterC
and VoidC
without Eff
wrapping them. See the benchmark
component for details.
WriterC | |
|