Community
Modules 24

Control.Monad.Writer.Class

experimental

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.

class (Monoid w, Monad m) => MonadWriter w m

writer :: (a, w) -> m a

writer (a,w) embeds a simple writer action.

tell :: w -> m ()

tell w is an action that produces the output w.

listen :: m a -> m (a, w)

listen m is an action that executes the action m and adds its output to the value of the computation.

pass :: m (a, w -> w) -> m a

pass m is an action that executes the action m, which returns a value and a function, and returns the value, applying the function to the output.

listens :: MonadWriter w m => (w -> b) -> m a -> m (a, b)

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 w m => (w -> w) -> m a -> m a

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)

Instances

15
  • instance (Monoid w) => MonadWriter w ((,) w)
  • instance (Monoid w, Monad m) => MonadWriter w (CPS.WriterT w m)
  • instance (Monoid w, Monad m) => MonadWriter w (Lazy.WriterT w m)
  • instance (Monoid w, Monad m) => MonadWriter w (Strict.WriterT w m)
  • instance (Monoid w, Monad m) => MonadWriter w (CPSRWS.RWST r w s m)
  • instance (Monoid w, Monad m) => MonadWriter w (LazyRWS.RWST r w s m)
  • instance (Monoid w, Monad m) => MonadWriter w (StrictRWS.RWST r w s m)
  • instance MonadWriter w m => MonadWriter w (ExceptT e m)
  • instance MonadWriter w m => MonadWriter w (IdentityT m)
  • instance MonadWriter w m => MonadWriter w (MaybeT m)
  • instance MonadWriter w m => MonadWriter w (ReaderT r m)
  • instance MonadWriter w m => MonadWriter w (Lazy.StateT s m)
  • instance MonadWriter w m => MonadWriter w (Strict.StateT s m)
  • instance (Monoid w', MonadWriter w m) => MonadWriter w (AccumT w' m)

    There are two valid instances for AccumT. It could either:

    1. Lift the operations to the inner MonadWriter

    2. Handle the operations itself, à la a WriterT.

    This instance chooses (1), reflecting that the intent of AccumT as a type is different than that of WriterT.

  • instance (MonadWriter w m, MonadWriter w n) => MonadWriter w (Product m n)
Maintainer
libraries@haskell.org
Portability
non-portable (multi-param classes, functional dependencies)
Copyright
(c) Andy Gill 2001, (c) Oregon Graduate Institute of Science and Technology, 2001
License
BSD-style (see the file LICENSE)
Build record and source files

Community contribution. The service has not verified this documentation. The generator reported 6 diagnostics.

Target: Linux on x86-64. Some inferred types and resolved links are not available.

Generator: aihc-haddock-858b1951-web-1

Metadata snapshot: 032b29dc8ecd03eaae7b1a84a40ef8560125381762749b2f47333bc9a4f4bb8e

Open the dependency plan · Download the documentation model

Import a package

Enter a package name and an exact version from Hackage. The site contains imported versions only.