| 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 (type families) |
| 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.
- 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 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
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 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
| MonadTrans (WriterT w) | |
| Monad m => Monad (WriterT w m) | |
| Functor m => Functor (WriterT w m) | |
| MonadFix m => MonadFix (WriterT w m) | |
| MonadFail m => MonadFail (WriterT w m) | |
| (Functor m, Monad m) => Applicative (WriterT w m) | |
| MonadIO m => MonadIO (WriterT w m) | |
| (Functor m, MonadPlus m) => Alternative (WriterT w m) | |
| (Functor m, MonadPlus m) => MonadPlus (WriterT w m) | |
| type WriterType (WriterT w m) # | |
runWriterT :: Monoid w => WriterT w m a -> m (a, w) #
Unwrap a writer computation.
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)