| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Control.Monad.Ology.Specific.WriterT
Contents
Synopsis
- tell :: forall (m :: Type -> Type) w. Monad m => w -> WriterT w m ()
- listen :: forall (m :: Type -> Type) w a. Monad m => WriterT w m a -> WriterT w m (a, w)
- listens :: forall (m :: Type -> Type) w b a. Monad m => (w -> b) -> WriterT w m a -> WriterT w m (a, b)
- censor :: forall (m :: Type -> Type) w a. Monad m => (w -> w) -> WriterT w m a -> WriterT w m a
- newtype WriterT w (m :: Type -> Type) a = WriterT {
- runWriterT :: m (a, w)
- type Writer w = WriterT w Identity
- runWriter :: Writer w a -> (a, w)
- execWriter :: Writer w a -> w
- mapWriter :: ((a, w) -> (b, w')) -> Writer w a -> Writer w' b
- execWriterT :: Monad m => WriterT w m a -> m w
- mapWriterT :: (m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b
- writer :: forall (m :: Type -> Type) a w. Monad m => (a, w) -> WriterT w m a
- pass :: forall (m :: Type -> Type) w a. Monad m => WriterT w m (a, w -> w) -> WriterT w m a
- collect :: forall (m :: Type -> Type) w a. (Monad m, Monoid w) => WriterT w m a -> WriterT w m (a, w)
- evalWriterT :: Monad m => WriterT w m a -> m a
Documentation
tell :: forall (m :: Type -> Type) w. Monad m => w -> WriterT w m () #
is an action that produces the output tell ww.
listen :: forall (m :: Type -> Type) w a. Monad m => WriterT w m a -> WriterT w m (a, w) #
is an action that executes the action listen mm and adds its
output to the value of the computation.
runWriterT(listenm) =liftM(\ (a, w) -> ((a, w), w)) (runWriterTm)
listens :: forall (m :: Type -> Type) w b a. Monad m => (w -> b) -> WriterT w m a -> WriterT w m (a, b) #
is an action that executes the action listens f mm and adds
the result of applying f to the output to the value of the computation.
listensf m =liftM(id *** f) (listenm)runWriterT(listensf m) =liftM(\ (a, w) -> ((a, f w), w)) (runWriterTm)
censor :: forall (m :: Type -> Type) w a. Monad m => (w -> w) -> WriterT w m a -> WriterT w m a #
is an action that executes the action censor f mm and
applies the function f to its output, leaving the return value
unchanged.
censorf m =pass(liftM(\ x -> (x,f)) m)runWriterT(censorf m) =liftM(\ (a, w) -> (a, f w)) (runWriterTm)
newtype WriterT w (m :: Type -> Type) a #
A writer monad parameterized by:
w- the output to accumulate.m- The inner monad.
The return function produces the output mempty, while >>=
combines the outputs of the subcomputations using mappend.
Constructors
| WriterT | |
Fields
| |
Instances
runWriter :: Writer w a -> (a, w) #
Unwrap a writer computation as a (result, output) pair.
(The inverse of writer.)
execWriter :: Writer w a -> w #
Extract the output from a writer computation.
execWriterm =snd(runWriterm)
execWriterT :: Monad m => WriterT w m a -> m w #
Extract the output from a writer computation.
execWriterTm =liftMsnd(runWriterTm)
mapWriterT :: (m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b #
Map both the return value and output of a computation using the given function.
runWriterT(mapWriterTf m) = f (runWriterTm)
writer :: forall (m :: Type -> Type) a w. Monad m => (a, w) -> WriterT w m a #
Construct a writer computation from a (result, output) pair.
(The inverse of runWriter.)
pass :: forall (m :: Type -> Type) w a. Monad m => WriterT w m (a, w -> w) -> WriterT w m a #
is an action that executes the action pass mm, which returns
a value and a function, and returns the value, applying the function
to the output.
runWriterT(passm) =liftM(\ ((a, f), w) -> (a, f w)) (runWriterTm)
collect :: forall (m :: Type -> Type) w a. (Monad m, Monoid w) => WriterT w m a -> WriterT w m (a, w) Source #
evalWriterT :: Monad m => WriterT w m a -> m a Source #
Orphan instances
| Monoid w => TransConstraint MonadFail (WriterT w) Source # | |
| Monoid w => TransConstraint MonadFix (WriterT w) Source # | |
| Monoid w => TransConstraint MonadIO (WriterT w) Source # | |
| Monoid w => TransConstraint Applicative (WriterT w) Source # | |
Methods hasTransConstraint :: forall (m :: Type -> Type). Applicative m => Dict (Applicative (WriterT w m)) Source # | |
| TransConstraint Functor (WriterT w) Source # | |
| Monoid w => TransConstraint Monad (WriterT w) Source # | |
| Monoid w => TransConstraint MonadPlus (WriterT w) Source # | |
| Monoid w => TransConstraint MonadException (WriterT w) Source # | |
Methods hasTransConstraint :: forall (m :: Type -> Type). MonadException m => Dict (MonadException (WriterT w m)) Source # | |
| Monoid w => TransConstraint MonadExtract (WriterT w) Source # | |
Methods hasTransConstraint :: forall (m :: Type -> Type). MonadExtract m => Dict (MonadExtract (WriterT w m)) Source # | |
| Monoid w => TransConstraint MonadInner (WriterT w) Source # | |
Methods hasTransConstraint :: forall (m :: Type -> Type). MonadInner m => Dict (MonadInner (WriterT w m)) Source # | |
| (MonadCatch e m, Monoid w) => MonadCatch e (WriterT w m) Source # | |
| (MonadThrow e m, Monoid w) => MonadThrow e (WriterT w m) Source # | |
| Monoid w => MonadTransCoerce (WriterT w) Source # | |
| Monoid w => MonadTransHoist (WriterT w) Source # | |
| Monoid w => MonadTransTunnel (WriterT w) Source # | |
| Monoid w => MonadTransUnlift (WriterT w) Source # | |
Methods liftWithUnlift :: MonadIO m => (Unlift MonadTunnelIO (WriterT w) -> m r) -> WriterT w m r Source # getDiscardingUnlift :: forall (m :: Type -> Type). Monad m => WriterT w m (WUnlift MonadTunnelIO (WriterT w)) Source # | |
| Monoid w => TransConstraint (MonadCatch e) (WriterT w) Source # | |
Methods hasTransConstraint :: forall (m :: Type -> Type). MonadCatch e m => Dict (MonadCatch e (WriterT w m)) Source # | |
| Monoid w => TransConstraint (MonadThrow e) (WriterT w) Source # | |
Methods hasTransConstraint :: forall (m :: Type -> Type). MonadThrow e m => Dict (MonadThrow e (WriterT w m)) Source # | |
| (Monoid w, MonadException m) => MonadException (WriterT w m) Source # | |
| (MonadExtract m, Monoid w) => MonadExtract (WriterT w m) Source # | |
| (MonadInner m, Monoid w) => MonadInner (WriterT w m) Source # | |