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

Safe HaskellNone
LanguageHaskell98

Control.Monad.Chronicle.Class

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

Documentation

class Monad m => MonadChronicle c m | m -> c where Source #

Minimal complete definition

dictate, confess, memento, absolve, condemn, retcon, chronicle

Methods

dictate :: c -> m () Source #

dictate c is an action that records the output c.

Equivalent to tell for the Writer monad.

disclose :: Default a => 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 :: c -> m a Source #

confess c is an action that ends with a final record 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 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 :: m a -> 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 :: (c -> c) -> m a -> 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.

chronicle :: These c a -> m a Source #

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

Instances

MonadChronicle c m => MonadChronicle c (MaybeT m) Source # 

Methods

dictate :: c -> MaybeT m () Source #

disclose :: Default a => c -> MaybeT m a Source #

confess :: c -> MaybeT m a Source #

memento :: MaybeT m a -> MaybeT m (Either c a) Source #

absolve :: a -> MaybeT m a -> MaybeT m a Source #

condemn :: MaybeT m a -> MaybeT m a Source #

retcon :: (c -> c) -> MaybeT m a -> MaybeT m a Source #

chronicle :: These c a -> MaybeT m a Source #

Semigroup c => MonadChronicle c (These c) Source # 

Methods

dictate :: c -> These c () Source #

disclose :: Default a => c -> These c a Source #

confess :: c -> These c a Source #

memento :: These c a -> These c (Either c a) Source #

absolve :: a -> These c a -> These c a Source #

condemn :: These c a -> These c a Source #

retcon :: (c -> c) -> These c a -> These c a Source #

chronicle :: These c a -> These c a Source #

(Monoid w, MonadChronicle c m) => MonadChronicle c (WriterT w m) Source # 

Methods

dictate :: c -> WriterT w m () Source #

disclose :: Default a => c -> WriterT w m a Source #

confess :: c -> WriterT w m a Source #

memento :: WriterT w m a -> WriterT w m (Either c a) Source #

absolve :: a -> WriterT w m a -> WriterT w m a Source #

condemn :: WriterT w m a -> WriterT w m a Source #

retcon :: (c -> c) -> WriterT w m a -> WriterT w m a Source #

chronicle :: These c a -> WriterT w m a Source #

(Monoid w, MonadChronicle c m) => MonadChronicle c (WriterT w m) Source # 

Methods

dictate :: c -> WriterT w m () Source #

disclose :: Default a => c -> WriterT w m a Source #

confess :: c -> WriterT w m a Source #

memento :: WriterT w m a -> WriterT w m (Either c a) Source #

absolve :: a -> WriterT w m a -> WriterT w m a Source #

condemn :: WriterT w m a -> WriterT w m a Source #

retcon :: (c -> c) -> WriterT w m a -> WriterT w m a Source #

chronicle :: These c a -> WriterT w m a Source #

MonadChronicle c m => MonadChronicle c (StateT s m) Source # 

Methods

dictate :: c -> StateT s m () Source #

disclose :: Default a => c -> StateT s m a Source #

confess :: c -> StateT s m a Source #

memento :: StateT s m a -> StateT s m (Either c a) Source #

absolve :: a -> StateT s m a -> StateT s m a Source #

condemn :: StateT s m a -> StateT s m a Source #

retcon :: (c -> c) -> StateT s m a -> StateT s m a Source #

chronicle :: These c a -> StateT s m a Source #

MonadChronicle c m => MonadChronicle c (StateT s m) Source # 

Methods

dictate :: c -> StateT s m () Source #

disclose :: Default a => c -> StateT s m a Source #

confess :: c -> StateT s m a Source #

memento :: StateT s m a -> StateT s m (Either c a) Source #

absolve :: a -> StateT s m a -> StateT s m a Source #

condemn :: StateT s m a -> StateT s m a Source #

retcon :: (c -> c) -> StateT s m a -> StateT s m a Source #

chronicle :: These c a -> StateT s m a Source #

MonadChronicle c m => MonadChronicle c (ExceptT e m) Source # 

Methods

dictate :: c -> ExceptT e m () Source #

disclose :: Default a => c -> ExceptT e m a Source #

confess :: c -> ExceptT e m a Source #

memento :: ExceptT e m a -> ExceptT e m (Either c a) Source #

absolve :: a -> ExceptT e m a -> ExceptT e m a Source #

condemn :: ExceptT e m a -> ExceptT e m a Source #

retcon :: (c -> c) -> ExceptT e m a -> ExceptT e m a Source #

chronicle :: These c a -> ExceptT e m a Source #

(Error e, MonadChronicle c m) => MonadChronicle c (ErrorT e m) Source # 

Methods

dictate :: c -> ErrorT e m () Source #

disclose :: Default a => c -> ErrorT e m a Source #

confess :: c -> ErrorT e m a Source #

memento :: ErrorT e m a -> ErrorT e m (Either c a) Source #

absolve :: a -> ErrorT e m a -> ErrorT e m a Source #

condemn :: ErrorT e m a -> ErrorT e m a Source #

retcon :: (c -> c) -> ErrorT e m a -> ErrorT e m a Source #

chronicle :: These c a -> ErrorT e m a Source #

MonadChronicle c m => MonadChronicle c (IdentityT * m) Source # 

Methods

dictate :: c -> IdentityT * m () Source #

disclose :: Default a => c -> IdentityT * m a Source #

confess :: c -> IdentityT * m a Source #

memento :: IdentityT * m a -> IdentityT * m (Either c a) Source #

absolve :: a -> IdentityT * m a -> IdentityT * m a Source #

condemn :: IdentityT * m a -> IdentityT * m a Source #

retcon :: (c -> c) -> IdentityT * m a -> IdentityT * m a Source #

chronicle :: These c a -> IdentityT * m a Source #

(Semigroup c, Monad m) => MonadChronicle c (ChronicleT c m) Source # 

Methods

dictate :: c -> ChronicleT c m () Source #

disclose :: Default a => c -> ChronicleT c m a Source #

confess :: c -> ChronicleT c m a Source #

memento :: ChronicleT c m a -> ChronicleT c m (Either c a) Source #

absolve :: a -> ChronicleT c m a -> ChronicleT c m a Source #

condemn :: ChronicleT c m a -> ChronicleT c m a Source #

retcon :: (c -> c) -> ChronicleT c m a -> ChronicleT c m a Source #

chronicle :: These c a -> ChronicleT c m a Source #

MonadChronicle c m => MonadChronicle c (ReaderT * r m) Source # 

Methods

dictate :: c -> ReaderT * r m () Source #

disclose :: Default a => c -> ReaderT * r m a Source #

confess :: c -> ReaderT * r m a Source #

memento :: ReaderT * r m a -> ReaderT * r m (Either c a) Source #

absolve :: a -> ReaderT * r m a -> ReaderT * r m a Source #

condemn :: ReaderT * r m a -> ReaderT * r m a Source #

retcon :: (c -> c) -> ReaderT * r m a -> ReaderT * r m a Source #

chronicle :: These c a -> ReaderT * r m a Source #

(Monoid w, MonadChronicle c m) => MonadChronicle c (RWST r w s m) Source # 

Methods

dictate :: c -> RWST r w s m () Source #

disclose :: Default a => c -> RWST r w s m a Source #

confess :: c -> RWST r w s m a Source #

memento :: RWST r w s m a -> RWST r w s m (Either c a) Source #

absolve :: a -> RWST r w s m a -> RWST r w s m a Source #

condemn :: RWST r w s m a -> RWST r w s m a Source #

retcon :: (c -> c) -> RWST r w s m a -> RWST r w s m a Source #

chronicle :: These c a -> RWST r w s m a Source #

(Monoid w, MonadChronicle c m) => MonadChronicle c (RWST r w s m) Source # 

Methods

dictate :: c -> RWST r w s m () Source #

disclose :: Default a => c -> RWST r w s m a Source #

confess :: c -> RWST r w s m a Source #

memento :: RWST r w s m a -> RWST r w s m (Either c a) Source #

absolve :: a -> RWST r w s m a -> RWST r w s m a Source #

condemn :: RWST r w s m a -> RWST r w s m a Source #

retcon :: (c -> c) -> RWST r w s m a -> RWST r w s m a Source #

chronicle :: These c a -> RWST r w s m a Source #

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

Instances

(Semigroup c, MonadRWS r w s m) => MonadRWS r w s (ChronicleT c m) Source # 
(Semigroup c, MonadState s m) => MonadState s (ChronicleT c m) Source # 

Methods

get :: ChronicleT c m s #

put :: s -> ChronicleT c m () #

state :: (s -> (a, s)) -> ChronicleT c m a #

(Semigroup c, MonadReader r m) => MonadReader r (ChronicleT c m) Source # 

Methods

ask :: ChronicleT c m r #

local :: (r -> r) -> ChronicleT c m a -> ChronicleT c m a #

reader :: (r -> a) -> ChronicleT c m a #

(Semigroup c, MonadError e m) => MonadError e (ChronicleT c m) Source # 

Methods

throwError :: e -> ChronicleT c m a #

catchError :: ChronicleT c m a -> (e -> ChronicleT c m a) -> ChronicleT c m a #

(Semigroup c, MonadWriter w m) => MonadWriter w (ChronicleT c m) Source # 

Methods

writer :: (a, w) -> ChronicleT c m a #

tell :: w -> ChronicleT c m () #

listen :: ChronicleT c m a -> ChronicleT c m (a, w) #

pass :: ChronicleT c m (a, w -> w) -> ChronicleT c m a #

(Semigroup c, Monad m) => MonadChronicle c (ChronicleT c m) Source # 

Methods

dictate :: c -> ChronicleT c m () Source #

disclose :: Default a => c -> ChronicleT c m a Source #

confess :: c -> ChronicleT c m a Source #

memento :: ChronicleT c m a -> ChronicleT c m (Either c a) Source #

absolve :: a -> ChronicleT c m a -> ChronicleT c m a Source #

condemn :: ChronicleT c m a -> ChronicleT c m a Source #

retcon :: (c -> c) -> ChronicleT c m a -> ChronicleT c m a Source #

chronicle :: These c a -> ChronicleT c m a Source #

Semigroup c => MonadTrans (ChronicleT c) Source # 

Methods

lift :: Monad m => m a -> ChronicleT c m a #

(Semigroup c, Monad m) => Monad (ChronicleT c m) Source # 

Methods

(>>=) :: ChronicleT c m a -> (a -> ChronicleT c m b) -> ChronicleT c m b #

(>>) :: ChronicleT c m a -> ChronicleT c m b -> ChronicleT c m b #

return :: a -> ChronicleT c m a #

fail :: String -> ChronicleT c m a #

Functor m => Functor (ChronicleT c m) Source # 

Methods

fmap :: (a -> b) -> ChronicleT c m a -> ChronicleT c m b #

(<$) :: a -> ChronicleT c m b -> ChronicleT c m a #

(Semigroup c, MonadFix m) => MonadFix (ChronicleT c m) Source # 

Methods

mfix :: (a -> ChronicleT c m a) -> ChronicleT c m a #

(Semigroup c, Applicative m) => Applicative (ChronicleT c m) Source # 

Methods

pure :: a -> ChronicleT c m a #

(<*>) :: ChronicleT c m (a -> b) -> ChronicleT c m a -> ChronicleT c m b #

(*>) :: ChronicleT c m a -> ChronicleT c m b -> ChronicleT c m b #

(<*) :: ChronicleT c m a -> ChronicleT c m b -> ChronicleT c m a #

(Semigroup c, Monoid c, Applicative m, Monad m) => Alternative (ChronicleT c m) Source # 

Methods

empty :: ChronicleT c m a #

(<|>) :: ChronicleT c m a -> ChronicleT c m a -> ChronicleT c m a #

some :: ChronicleT c m a -> ChronicleT c m [a] #

many :: ChronicleT c m a -> ChronicleT c m [a] #

(Semigroup c, Monoid c, Monad m) => MonadPlus (ChronicleT c m) Source # 

Methods

mzero :: ChronicleT c m a #

mplus :: ChronicleT c m a -> ChronicleT c m a -> ChronicleT c m a #

(Semigroup c, MonadIO m) => MonadIO (ChronicleT c m) Source # 

Methods

liftIO :: IO a -> ChronicleT c m a #

(Semigroup c, Apply m) => Apply (ChronicleT c m) Source # 

Methods

(<.>) :: ChronicleT c m (a -> b) -> ChronicleT c m a -> ChronicleT c m b #

(.>) :: ChronicleT c m a -> ChronicleT c m b -> ChronicleT c m b #

(<.) :: ChronicleT c m a -> ChronicleT c m b -> ChronicleT c m a #

(Semigroup c, Apply m, Monad m) => Bind (ChronicleT c m) Source # 

Methods

(>>-) :: ChronicleT c m a -> (a -> ChronicleT c m b) -> ChronicleT c m b #

join :: ChronicleT c m (ChronicleT c m a) -> ChronicleT c m a #