# Control.Monad.Writer

- Package
- purescript-transformers
- Repository
- purescript/purescript-transformers

This module defines the `Writer`

monad.

### #execWriter Source

`execWriter :: forall a w. Writer w a -> w`

Run a computation in the `Writer`

monad, discarding the result

## Re-exports from **Control.**Monad.Writer.Class

### #MonadTell Source

`class (Monad m) <= MonadTell w m | m -> w where`

The `MonadTell w`

type class represents those monads which support a
monoidal accumulator of type `w`

, were `tell`

appends a value to the
accumulator.

An implementation is provided for `WriterT`

, and for other monad
transformers defined in this library.

Law:

`do { tell x ; tell y } = tell (x <> y)`

#### Members

### #MonadWriter Source

`class (MonadTell w m) <= MonadWriter w m | m -> w where`

An extension of the `MonadTell`

class that introduces some operations on
the accumulator:

`listen`

modifies the result to include the changes to the accumulator.`pass`

applies the returned function to the accumulator.

An implementation is provided for `WriterT`

, and for other monad
transformers defined in this library.

Laws in addition to the `MonadTell`

law:

`do { tell x ; tell y } = tell (x <> y)`

`listen (pure a) = pure (Tuple a mempty)`

`listen (writer a x) = tell x $> Tuple a x`

#### Members

### #listens Source

`listens :: forall b a m w. MonadWriter w m => (w -> b) -> m a -> m (Tuple a b)`

Projects a value from modifications made to the accumulator during an action.

### #censor Source

`censor :: forall a m w. MonadWriter w m => (w -> w) -> m a -> m a`

Modify the final accumulator value by applying a function.

## Re-exports from **Control.**Monad.Writer.Trans

### #WriterT Source

`newtype WriterT w m a`

The writer monad transformer.

This monad transformer extends the base monad with a monoidal accumulator of
type `w`

.

The `MonadWriter`

type class describes the operations supported by this monad.

#### Constructors

#### Instances

`Newtype (WriterT w m a) _`

`(Functor m) => Functor (WriterT w m)`

`(Semigroup w, Apply m) => Apply (WriterT w m)`

`(Monoid w, Applicative m) => Applicative (WriterT w m)`

`(Alt m) => Alt (WriterT w m)`

`(Plus m) => Plus (WriterT w m)`

`(Monoid w, Alternative m) => Alternative (WriterT w m)`

`(Semigroup w, Bind m) => Bind (WriterT w m)`

`(Monoid w, Monad m) => Monad (WriterT w m)`

`(Monoid w, MonadRec m) => MonadRec (WriterT w m)`

`(Monoid w, MonadZero m) => MonadZero (WriterT w m)`

`(Monoid w, MonadPlus m) => MonadPlus (WriterT w m)`

`(Monoid w) => MonadTrans (WriterT w)`

`(Monoid w, MonadEff eff m) => MonadEff eff (WriterT w m)`

`(Monoid w, MonadCont m) => MonadCont (WriterT w m)`

`(Monoid w, MonadThrow e m) => MonadThrow e (WriterT w m)`

`(Monoid w, MonadError e m) => MonadError e (WriterT w m)`

`(Monoid w, MonadAsk r m) => MonadAsk r (WriterT w m)`

`(Monoid w, MonadReader r m) => MonadReader r (WriterT w m)`

`(Monoid w, MonadState s m) => MonadState s (WriterT w m)`

`(Monoid w, Monad m) => MonadTell w (WriterT w m)`

`(Monoid w, Monad m) => MonadWriter w (WriterT w m)`

### #MonadTrans Source

`class MonadTrans t where`

The `MonadTrans`

type class represents *monad transformers*.

A monad transformer is a type constructor of kind `(* -> *) -> * -> *`

, which
takes a `Monad`

as its first argument, and returns another `Monad`

.

This allows us to add additional effects to an existing monad. By iterating this
process, we create monad transformer *stacks*, which contain all of the effects
required for a particular computation.

The laws state that `lift`

is a `Monad`

morphism.

Laws:

`lift (pure a) = pure a`

`lift (do { x <- m ; y }) = do { x <- lift m ; lift y }`

#### Members

### #runWriterT Source

`runWriterT :: forall a m w. WriterT w m a -> m (Tuple a w)`

Run a computation in the `WriterT`

monad.

### #mapWriterT Source

`mapWriterT :: forall b a m2 m1 w2 w1. (m1 (Tuple a w1) -> m2 (Tuple b w2)) -> WriterT w1 m1 a -> WriterT w2 m2 b`

Change the accumulator and base monad types in a `WriterT`

monad action.

### #execWriterT Source

`execWriterT :: forall a m w. Functor m => WriterT w m a -> m w`

Run a computation in the `WriterT`

monad, discarding the result.

- Modules
- Control.
Comonad. Env - Control.
Comonad. Env. Class - Control.
Comonad. Env. Trans - Control.
Comonad. Store - Control.
Comonad. Store. Class - Control.
Comonad. Store. Trans - Control.
Comonad. Traced - Control.
Comonad. Traced. Class - Control.
Comonad. Traced. Trans - Control.
Comonad. Trans. Class - Control.
Monad. Cont - Control.
Monad. Cont. Class - Control.
Monad. Cont. Trans - Control.
Monad. Error. Class - Control.
Monad. Except - Control.
Monad. Except. Trans - Control.
Monad. List. Trans - Control.
Monad. Maybe. Trans - Control.
Monad. RWS - Control.
Monad. RWS. Trans - Control.
Monad. Reader - Control.
Monad. Reader. Class - Control.
Monad. Reader. Trans - Control.
Monad. State - Control.
Monad. State. Class - Control.
Monad. State. Trans - Control.
Monad. Trans. Class - Control.
Monad. Writer - Control.
Monad. Writer. Class - Control.
Monad. Writer. Trans