monads-tf-0.3.0.1: Monad classes, using type families

Copyright | (c) Andy Gill 2001 (c) Oregon Graduate Institute of Science and Technology 2001
License | BSD-style (see the file LICENSE)
Maintainer | ross@soi.city.ac.uk
Stability | experimental
Portability | non-portable (type families)
Safe Haskell | None
Language | GHC2021

Control.Monad.Writer.Class

Description

The MonadWriter class.

Inspired by the paper /Functional Programming with Overloading and Higher-Order Polymorphism/, Mark P Jones (http://web.cecs.pdx.edu/~mpj/pubs/springschool.html) Advanced School of Functional Programming, 1995.

Synopsis

- class (Monoid (WriterType m), Monad m) => MonadWriter (m :: Type -> Type) where
  - type WriterType (m :: Type -> Type)
  - tell :: WriterType m -> m ()
  - listen :: m a -> m (a, WriterType m)
  - pass :: m (a, WriterType m -> WriterType m) -> m a
- listens :: MonadWriter m => (WriterType m -> b) -> m a -> m (a, b)
- censor :: MonadWriter m => (WriterType m -> WriterType m) -> m a -> m a

# Documentation

class (Monoid (WriterType m), Monad m) => MonadWriter (m :: Type -> Type) where Source #

Associated Types

type WriterType (m :: Type -> Type) Source #

Methods

tell :: WriterType m -> m () Source #

Shout to the monad what you want to be heard. The monad carries this packet upwards, merging it if needed (hence the `Monoid` requirement).

listen :: m a -> m (a, WriterType m) Source #

Listen to a monad acting, and return what the monad "said".

pass :: m (a, WriterType m -> WriterType m) -> m a Source #

Provide a writer transformer which changes internals of the written object.

#### Instances

Instances details

MonadWriter m => MonadWriter (MaybeT m) Source # |

Instance details

Defined in Control.Monad.Writer.Class

Associated Types

type WriterType (MaybeT m) |
Instance details Defined in Control.Monad.Writer.Class type WriterType (MaybeT m) = WriterType m

Methods

tell :: WriterType (MaybeT m) -> MaybeT m () Source #

listen :: MaybeT m a -> MaybeT m (a, WriterType (MaybeT m)) Source #

pass :: MaybeT m (a, WriterType (MaybeT m) -> WriterType (MaybeT m)) -> MaybeT m a Source #

MonadWriter m => MonadWriter (ExceptT e m) Source # |

Instance details

Defined in Control.Monad.Writer.Class

Associated Types

type WriterType (ExceptT e m) |
Instance details Defined in Control.Monad.Writer.Class type WriterType (ExceptT e m) = WriterType m

Methods

tell :: WriterType (ExceptT e m) -> ExceptT e m () Source #

listen :: ExceptT e m a -> ExceptT e m (a, WriterType (ExceptT e m)) Source #

pass :: ExceptT e m (a, WriterType (ExceptT e m) -> WriterType (ExceptT e m)) -> ExceptT e m a Source #

MonadWriter m => MonadWriter (IdentityT m) Source # |

Instance details

Defined in Control.Monad.Writer.Class

Associated Types

type WriterType (IdentityT m) |
Instance details Defined in Control.Monad.Writer.Class type WriterType (IdentityT m) = WriterType m

Methods

tell :: WriterType (IdentityT m) -> IdentityT m () Source #

listen :: IdentityT m a -> IdentityT m (a, WriterType (IdentityT m)) Source #

pass :: IdentityT m (a, WriterType (IdentityT m) -> WriterType (IdentityT m)) -> IdentityT m a Source #

MonadWriter m => MonadWriter (ReaderT r m) Source # |

Instance details

Defined in Control.Monad.Writer.Class

Associated Types

type WriterType (ReaderT r m) |
Instance details Defined in Control.Monad.Writer.Class type WriterType (ReaderT r m) = WriterType m

Methods

tell :: WriterType (ReaderT r m) -> ReaderT r m () Source #

listen :: ReaderT r m a -> ReaderT r m (a, WriterType (ReaderT r m)) Source #

pass :: ReaderT r m (a, WriterType (ReaderT r m) -> WriterType (ReaderT r m)) -> ReaderT r m a Source #

MonadWriter m => MonadWriter (StateT s m) Source # |

Instance details

Defined in Control.Monad.Writer.Class

Associated Types

type WriterType (StateT s m) |
Instance details Defined in Control.Monad.Writer.Class type WriterType (StateT s m) = WriterType m

Methods

tell :: WriterType (StateT s m) -> StateT s m () Source #

listen :: StateT s m a -> StateT s m (a, WriterType (StateT s m)) Source #

pass :: StateT s m (a, WriterType (StateT s m) -> WriterType (StateT s m)) -> StateT s m a Source #

MonadWriter m => MonadWriter (StateT s m) Source # |

Instance details

Defined in Control.Monad.Writer.Class

Associated Types

type WriterType (StateT s m) |
Instance details Defined in Control.Monad.Writer.Class type WriterType (StateT s m) = WriterType m

Methods

tell :: WriterType (StateT s m) -> StateT s m () Source #

listen :: StateT s m a -> StateT s m (a, WriterType (StateT s m)) Source #

pass :: StateT s m (a, WriterType (StateT s m) -> WriterType (StateT s m)) -> StateT s m a Source #

(Monoid w, Monad m) => MonadWriter (WriterT w m) Source # |

Instance details

Defined in Control.Monad.Writer.Class

Associated Types

type WriterType (WriterT w m) |
Instance details Defined in Control.Monad.Writer.Class type WriterType (WriterT w m) = w

Methods

tell :: WriterType (WriterT w m) -> WriterT w m () Source #

listen :: WriterT w m a -> WriterT w m (a, WriterType (WriterT w m)) Source #

pass :: WriterT w m (a, WriterType (WriterT w m) -> WriterType (WriterT w m)) -> WriterT w m a Source #

(Monoid w, Monad m) => MonadWriter (WriterT w m) Source # |

Instance details

Defined in Control.Monad.Writer.Class

Associated Types

type WriterType (WriterT w m) |
Instance details Defined in Control.Monad.Writer.Class type WriterType (WriterT w m) = w

Methods

tell :: WriterType (WriterT w m) -> WriterT w m () Source #

listen :: WriterT w m a -> WriterT w m (a, WriterType (WriterT w m)) Source #

pass :: WriterT w m (a, WriterType (WriterT w m) -> WriterType (WriterT w m)) -> WriterT w m a Source #

(Monoid w, Monad m) => MonadWriter (RWST r w s m) Source # |

Instance details

Defined in Control.Monad.Writer.Class

Associated Types

type WriterType (RWST r w s m) |
Instance details Defined in Control.Monad.Writer.Class type WriterType (RWST r w s m) = w

Methods

tell :: WriterType (RWST r w s m) -> RWST r w s m () Source #

listen :: RWST r w s m a -> RWST r w s m (a, WriterType (RWST r w s m)) Source #

pass :: RWST r w s m (a, WriterType (RWST r w s m) -> WriterType (RWST r w s m)) -> RWST r w s m a Source #

(Monoid w, Monad m) => MonadWriter (RWST r w s m) Source # |

Instance details

Defined in Control.Monad.Writer.Class

Associated Types

type WriterType (RWST r w s m) |
Instance details Defined in Control.Monad.Writer.Class type WriterType (RWST r w s m) = w

Methods

tell :: WriterType (RWST r w s m) -> RWST r w s m () Source #

listen :: RWST r w s m a -> RWST r w s m (a, WriterType (RWST r w s m)) Source #

pass :: RWST r w s m (a, WriterType (RWST r w s m) -> WriterType (RWST r w s m)) -> RWST r w s m a Source #

listens :: MonadWriter m => (WriterType m -> b) -> m a -> m (a, b) Source #

``listens` f m` is an action that executes the action `m` and adds the result of applying `f` to the output to the value of the computation.

-     listens f m = liftM (id *** f) (listen m)

censor :: MonadWriter m => (WriterType m -> WriterType m) -> m a -> m a Source #

``censor` f m` is an action that executes the action `m` and applies the function `f` to its output, leaving the return value unchanged.

-     censor f m = pass (liftM (\ x -> (x,f)) m)