planet-mitchell-0.0.0: Planet Mitchell

Safe HaskellSafe
LanguageHaskell2010

Writer

Contents

Synopsis

Writer

type Writer w = WriterT w Identity #

A writer monad parameterized by the type w of output to accumulate.

The return function produces the output mempty, while >>= combines the outputs of the subcomputations using mappend.

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.

mapWriter :: (Monoid w, Monoid w') => ((a, w) -> (b, w')) -> Writer w a -> Writer w' b #

Map both the return value and output of a computation using the given function.

WriterT

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) 
Instance details

Defined in Control.Monad.Trans.Writer.CPS.Internal

Methods

lift :: Monad m => m a -> WriterT w m a #

Monad m => Monad (WriterT w m) 
Instance details

Defined in Control.Monad.Trans.Writer.CPS.Internal

Methods

(>>=) :: WriterT w m a -> (a -> WriterT w m b) -> WriterT w m b #

(>>) :: WriterT w m a -> WriterT w m b -> WriterT w m b #

return :: a -> WriterT w m a #

fail :: String -> WriterT w m a #

Functor m => Functor (WriterT w m) 
Instance details

Defined in Control.Monad.Trans.Writer.CPS.Internal

Methods

fmap :: (a -> b) -> WriterT w m a -> WriterT w m b #

(<$) :: a -> WriterT w m b -> WriterT w m a #

MonadFix m => MonadFix (WriterT w m) 
Instance details

Defined in Control.Monad.Trans.Writer.CPS.Internal

Methods

mfix :: (a -> WriterT w m a) -> WriterT w m a #

MonadFail m => MonadFail (WriterT w m) 
Instance details

Defined in Control.Monad.Trans.Writer.CPS.Internal

Methods

fail :: String -> WriterT w m a #

(Functor m, Monad m) => Applicative (WriterT w m) 
Instance details

Defined in Control.Monad.Trans.Writer.CPS.Internal

Methods

pure :: a -> WriterT w m a #

(<*>) :: WriterT w m (a -> b) -> WriterT w m a -> WriterT w m b #

liftA2 :: (a -> b -> c) -> WriterT w m a -> WriterT w m b -> WriterT w m c #

(*>) :: WriterT w m a -> WriterT w m b -> WriterT w m b #

(<*) :: WriterT w m a -> WriterT w m b -> WriterT w m a #

(Functor m, MonadPlus m) => Alternative (WriterT w m) 
Instance details

Defined in Control.Monad.Trans.Writer.CPS.Internal

Methods

empty :: WriterT w m a #

(<|>) :: WriterT w m a -> WriterT w m a -> WriterT w m a #

some :: WriterT w m a -> WriterT w m [a] #

many :: WriterT w m a -> WriterT w m [a] #

(Functor m, MonadPlus m) => MonadPlus (WriterT w m) 
Instance details

Defined in Control.Monad.Trans.Writer.CPS.Internal

Methods

mzero :: WriterT w m a #

mplus :: WriterT w m a -> WriterT w m a -> WriterT w m a #

MonadIO m => MonadIO (WriterT w m) 
Instance details

Defined in Control.Monad.Trans.Writer.CPS.Internal

Methods

liftIO :: IO a -> WriterT w m a #

writerT :: (Functor m, Monoid w) => m (a, w) -> WriterT w m a #

The WriterT constructor is deliberately not exported in the CPS module to avoid exposing the hidden state w. writerT provides a safe way to construct a WriterT with the same api as the original WriterT.

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.

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.

MonadWriter

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

Minimal complete definition

(writer | tell), listen, pass

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 (GenT m) 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

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

tell :: w -> GenT m () #

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

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

MonadWriter w m => MonadWriter w (MaybeT m) 
Instance details

Defined in Control.Monad.Writer.Class

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 #

Monoid w => MonadWriter w ((,) w)

NOTE: This instance is only defined for base >= 4.9.0.

Since: mtl-2.2.2

Instance details

Defined in Control.Monad.Writer.Class

Methods

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

tell :: w -> (w, ()) #

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

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

(Functor m, MonadWriter e m) => MonadWriter e (Free m) 
Instance details

Defined in Control.Monad.Free

Methods

writer :: (a, e) -> Free m a #

tell :: e -> Free m () #

listen :: Free m a -> Free m (a, e) #

pass :: Free m (a, e -> e) -> Free m a #

(Monoid w, Monad m) => MonadWriter w (WriterT w m) 
Instance details

Defined in Control.Monad.Writer.Class

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) 
Instance details

Defined in Control.Monad.Writer.Class

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 (StateT s m) 
Instance details

Defined in Control.Monad.Writer.Class

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) 
Instance details

Defined in Control.Monad.Writer.Class

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) 
Instance details

Defined in Control.Monad.Writer.Class

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)

Since: mtl-2.2

Instance details

Defined in Control.Monad.Writer.Class

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) 
Instance details

Defined in Control.Monad.Writer.Class

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 #

(Functor f, MonadWriter w m) => MonadWriter w (FreeT f m) 
Instance details

Defined in Control.Monad.Trans.Free

Methods

writer :: (a, w) -> FreeT f m a #

tell :: w -> FreeT f m () #

listen :: FreeT f m a -> FreeT f m (a, w) #

pass :: FreeT f m (a, w -> w) -> FreeT f m a #

MonadWriter w m => MonadWriter w (ReaderT r m) 
Instance details

Defined in Control.Monad.Writer.Class

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) 
Instance details

Defined in Control.Monad.Writer.Class

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) 
Instance details

Defined in Control.Monad.Writer.Class

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.

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.