these-0.4.2: An either-or-both data type, with corresponding hybrid error/writer monad transformer.

Safe HaskellSafe-Inferred

Control.Monad.Trans.Chronicle

Contents

Description

The ChronicleT monad, a hybrid error/writer monad that allows both accumulating outputs and aborting computation with a final output.

Synopsis

The Chronicle monad

type Chronicle c = ChronicleT c IdentitySource

A chronicle monad parameterized by the output type c.

The return function produces a computation with no output, and >>= combines multiple outputs with mappend.

The ChronicleT monad transformer

newtype ChronicleT c m a Source

The ChronicleT monad transformer.

The return function produces a computation with no output, and >>= combines multiple outputs with mappend.

Constructors

ChronicleT 

Fields

runChronicleT :: m (These c a)
 

Instances

(Monoid c, MonadRWS r w s m) => MonadRWS r w s (ChronicleT c m) 
(Monoid c, MonadError e m) => MonadError e (ChronicleT c m) 
(Monoid c, MonadReader r m) => MonadReader r (ChronicleT c m) 
(Monoid c, MonadState s m) => MonadState s (ChronicleT c m) 
(Monoid c, MonadWriter w m) => MonadWriter w (ChronicleT c m) 
(Monoid c, Monad m) => MonadChronicle c (ChronicleT c m) 
Monoid c => MonadTrans (ChronicleT c) 
(Monoid c, Monad m) => Monad (ChronicleT c m) 
Functor m => Functor (ChronicleT c m) 
(Monoid c, Monad m) => MonadPlus (ChronicleT c m) 
(Monoid c, Applicative m) => Applicative (ChronicleT c m) 
(Monoid c, Applicative m, Monad m) => Alternative (ChronicleT c m) 
(Monoid c, MonadIO m) => MonadIO (ChronicleT c m) 
(Monoid c, Apply m) => Apply (ChronicleT c m) 
(Monoid c, Apply m, Monad m) => Bind (ChronicleT c m) 

Chronicle operations

dictate :: (Monoid c, Monad m) => c -> ChronicleT c m ()Source

dictate c is an action that records the output c.

Equivalent to tell for the Writer monad.

confess :: (Monoid c, Monad m) => c -> ChronicleT c m aSource

confess c is an action that ends with a final output c.

Equivalent to throwError for the Error monad.

memento :: (Monoid c, Monad m) => ChronicleT c m a -> ChronicleT c m (Either c a)Source

memento m is an action that executes the action m, returning either its record if it ended with confess, or its final value otherwise, with any record added to the current record.

Similar to catchError in the Error monad, but with a notion of non-fatal errors (which are accumulated) vs. fatal errors (which are caught without accumulating).

absolve :: (Monoid c, Monad m) => a -> ChronicleT c m a -> ChronicleT c m aSource

absolve x m is an action that executes the action m and discards any record it had. The default value x will be used if m ended via confess.

condemn :: (Monoid c, Monad m) => ChronicleT c m a -> ChronicleT c m aSource

condemn m is an action that executes the action m and keeps its value only if it had no record. Otherwise, the value (if any) will be discarded and only the record kept.

This can be seen as converting non-fatal errors into fatal ones.

retcon :: (Monoid c, Monad m) => (c -> c) -> ChronicleT c m a -> ChronicleT c m aSource

retcon f m is an action that executes the action m and applies the function f to its output, leaving the return value unchanged.

Equivalent to censor for the Writer monad.