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

Safe HaskellNone



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.


class Monad m => MonadChronicle c m | m -> c whereSource


dictate :: c -> m ()Source

dictate c is an action that records the output c.

Equivalent to tell for the Writer monad.

confess :: c -> m aSource

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

Equivalent to throwError for the Error monad.

memento :: m a -> 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 :: a -> m a -> 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 :: m a -> 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 :: (c -> c) -> m a -> 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.

chronicle :: These c a -> m aSource

chronicle m lifts a plain 'These c a' value into a MonadChronicle instance.