these-0.6.2.1: An either-or-both data type & a generalized 'zip with padding' typeclass

Safe HaskellSafe
LanguageHaskell98

Control.Monad.Trans.Chronicle

Contents

Description

Hybrid error/writer monad class that allows both accumulating outputs and aborting computation with a final output.

The expected use case is for computations with a notion of fatal vs. non-fatal errors.

Synopsis

The Chronicle monad

type Chronicle c = ChronicleT c Identity Source

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)
 

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.

disclose :: (Default a, Monoid c, Monad m) => c -> ChronicleT c m a Source

disclose c is an action that records the output c and returns a Default value.

This is a convenience function for reporting non-fatal errors in one branch a case, or similar scenarios when there is no meaningful result but a placeholder of sorts is needed in order to continue.

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

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 a Source

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 a Source

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 a Source

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.