mtl-2.2.1: Monad classes, using functional dependencies

Copyright | (c) Andy Gill 2001 (c) Oregon Graduate Institute of Science and Technology 2001
License | BSD-style (see the file LICENSE)
Maintainer | libraries@haskell.org
Stability | experimental
Portability | non-portable (multi-param classes, functional dependencies)
Safe Haskell | Safe
Language | Haskell98

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 w, Monad m) => MonadWriter w m | m -> w where
- listens :: MonadWriter w m => (w -> b) -> m a -> m (a, b)
- censor :: MonadWriter w m => (w -> w) -> m a -> m a

# Documentation

class (Monoid w, Monad m) => MonadWriter w m | m -> w where #

Methods

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.

Instances

MonadWriter w m => MonadWriter w (MaybeT m) # |
Methods writer :: (a, w) -> MaybeT m a # tell :: w -> MaybeT m () # listen :: MaybeT m a -> MaybeT m (a, w) # pass :: MaybeT m (a, w -> w) -> MaybeT m a #
MonadWriter w m => MonadWriter w (StateT s m) # |
Methods writer :: (a, w) -> StateT s m a # tell :: w -> StateT s m () # listen :: StateT s m a -> StateT s m (a, w) # pass :: StateT s m (a, w -> w) -> StateT s m a #
MonadWriter w m => MonadWriter w (StateT s m) # |
Methods writer :: (a, w) -> StateT s m a # tell :: w -> StateT s m () # listen :: StateT s m a -> StateT s m (a, w) # pass :: StateT s m (a, w -> w) -> StateT s m a #
MonadWriter w m => MonadWriter w (IdentityT * m) # |
Methods writer :: (a, w) -> IdentityT * m a # tell :: w -> IdentityT * m () # listen :: IdentityT * m a -> IdentityT * m (a, w) # pass :: IdentityT * m (a, w -> w) -> IdentityT * m a #
MonadWriter w m => MonadWriter w (ExceptT e m) # |
Methods writer :: (a, w) -> ExceptT e m a # tell :: w -> ExceptT e m () # listen :: ExceptT e m a -> ExceptT e m (a, w) # pass :: ExceptT e m (a, w -> w) -> ExceptT e m a #
(Error e, MonadWriter w m) => MonadWriter w (ErrorT e m) # |
Methods writer :: (a, w) -> ErrorT e m a # tell :: w -> ErrorT e m () # listen :: ErrorT e m a -> ErrorT e m (a, w) # pass :: ErrorT e m (a, w -> w) -> ErrorT e m a #
(Monoid w, Monad m) => MonadWriter w (WriterT w m) # |
Methods writer :: (a, w) -> WriterT w m a # tell :: w -> WriterT w m () # listen :: WriterT w m a -> WriterT w m (a, w) # pass :: WriterT w m (a, w -> w) -> WriterT w m a #
(Monoid w, Monad m) => MonadWriter w (WriterT w m) # |
Methods writer :: (a, w) -> WriterT w m a # tell :: w -> WriterT w m () # listen :: WriterT w m a -> WriterT w m (a, w) # pass :: WriterT w m (a, w -> w) -> WriterT w m a #
MonadWriter w m => MonadWriter w (ReaderT * r m) # |
Methods writer :: (a, w) -> ReaderT * r m a # tell :: w -> ReaderT * r m () # listen :: ReaderT * r m a -> ReaderT * r m (a, w) # pass :: ReaderT * r m (a, w -> w) -> ReaderT * r m a #
(Monoid w, Monad m) => MonadWriter w (RWST r w s m) # |
Methods writer :: (a, w) -> RWST r w s m a # tell :: w -> RWST r w s m () # listen :: RWST r w s m a -> RWST r w s m (a, w) # pass :: RWST r w s m (a, w -> w) -> RWST r w s m a #
(Monoid w, Monad m) => MonadWriter w (RWST r w s m) # |
Methods writer :: (a, w) -> RWST r w s m a # tell :: w -> RWST r w s m () # listen :: RWST r w s m a -> RWST r w s m (a, w) # pass :: RWST r w s m (a, w -> w) -> RWST r w s m a #

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)