| Copyright | (c) Daniel Mendler 2016 (c) Andy Gill 2001 (c) Oregon Graduate Institute of Science and Technology 2001 |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | mail@daniel-mendler.de |
| Stability | experimental |
| Portability | non-portable (multi-param classes, functional dependencies) |
| Safe Haskell | Safe |
| Language | Haskell2010 |
Control.Monad.Writer.CPS
Description
Stricter writer monad using continuation-passing-style for the writer output.
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
- type Writer w = WriterT w Identity
- runWriter :: Monoid w => Writer w a -> (a, w)
- execWriter :: Monoid w => Writer w a -> w
- mapWriter :: (Monoid w, Monoid w') => ((a, w) -> (b, w')) -> Writer w a -> Writer w' b
- data WriterT w (m :: Type -> Type) a
- writerT :: (Functor m, Monoid w) => m (a, w) -> WriterT w m a
- runWriterT :: Monoid w => WriterT w m a -> m (a, w)
- execWriterT :: (Monad m, Monoid w) => WriterT w m a -> m w
- mapWriterT :: (Monad n, Monoid w, Monoid w') => (m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b
- module Data.Monoid
- module Control.Monad.Writer.Class
- module Control.Monad.Trans
- module Control.Monad.Fix
- module Control.Monad
The Writer monad
runWriter :: Monoid w => Writer w a -> (a, w) #
Unwrap a writer computation as a (result, output) pair.
(The inverse of writer.)
execWriter :: Monoid w => Writer w a -> w #
Extract the output from a writer computation.
execWriterm =snd(runWriterm)
The WriterT monad transformer
data 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.
Instances
| (Monad m, Monoid w) => MonadWriter w (WriterT w m) Source # | |
| MonadState s m => MonadState s (WriterT w m) Source # | |
| (MonadReader r m, Monoid w) => MonadReader r (WriterT w m) Source # | |
| MonadError e m => MonadError e (WriterT w m) Source # | |
Defined in Control.Monad.Writer.CPS Methods throwError :: e -> WriterT w m a # catchError :: WriterT w m a -> (e -> WriterT w m a) -> WriterT w m a # | |
| MonadTrans (WriterT w) | |
Defined in Control.Monad.Trans.Writer.CPS | |
| Monad m => Monad (WriterT w m) | |
| Functor m => Functor (WriterT w m) | |
| MonadFix m => MonadFix (WriterT w m) | |
Defined in Control.Monad.Trans.Writer.CPS | |
| MonadFail m => MonadFail (WriterT w m) | |
Defined in Control.Monad.Trans.Writer.CPS | |
| (Functor m, Monad m) => Applicative (WriterT w m) | |
Defined in Control.Monad.Trans.Writer.CPS | |
| MonadIO m => MonadIO (WriterT w m) | |
Defined in Control.Monad.Trans.Writer.CPS | |
| (Functor m, MonadPlus m) => Alternative (WriterT w m) | |
| (Functor m, MonadPlus m) => MonadPlus (WriterT w m) | |
| MonadCont m => MonadCont (WriterT w m) Source # | |
writerT :: (Functor m, Monoid w) => m (a, w) -> WriterT w m a #
Construct a writer computation from a (result, output) computation.
(The inverse of runWriterT.)
runWriterT :: Monoid w => WriterT w m a -> m (a, w) #
Unwrap a writer computation.
(The inverse of writerT.)
execWriterT :: (Monad m, Monoid w) => WriterT w m a -> m w #
Extract the output from a writer computation.
execWriterTm =liftMsnd(runWriterTm)
mapWriterT :: (Monad n, Monoid w, Monoid w') => (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)
module Data.Monoid
module Control.Monad.Writer.Class
module Control.Monad.Trans
module Control.Monad.Fix
module Control.Monad
Orphan instances
| (Monad m, Monoid w) => MonadWriter w (WriterT w m) Source # | |
| MonadState s m => MonadState s (WriterT w m) Source # | |
| (MonadReader r m, Monoid w) => MonadReader r (WriterT w m) Source # | |
| MonadError e m => MonadError e (WriterT w m) Source # | |
Methods throwError :: e -> WriterT w m a # catchError :: WriterT w m a -> (e -> WriterT w m a) -> WriterT w m a # | |
| MonadCont m => MonadCont (WriterT w m) Source # | |