monad-chronicle-1.1: These as a transformer, ChronicleT

Safe Haskell | Trustworthy
Language | Haskell2010

Control.Monad.Trans.Chronicle

Contents

- The Chronicle monad
- The ChronicleT monad transformer
- Chronicle operations

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

- type Chronicle c = ChronicleT c Identity
- chronicle :: forall (m :: Type -> Type) c a. Monad m => These c a -> ChronicleT c m a
- runChronicle :: Chronicle c a -> These c a
- newtype ChronicleT c (m :: Type -> Type) a = ChronicleT {
  - runChronicleT :: m (These c a)
  }
- dictate :: forall c (m :: Type -> Type). (Semigroup c, Monad m) => c -> ChronicleT c m ()
- confess :: forall c (m :: Type -> Type) a. (Semigroup c, Monad m) => c -> ChronicleT c m a
- memento :: forall c (m :: Type -> Type) a. (Semigroup c, Monad m) => ChronicleT c m a -> ChronicleT c m (Either c a)
- absolve :: forall c (m :: Type -> Type) a. (Semigroup c, Monad m) => a -> ChronicleT c m a -> ChronicleT c m a
- condemn :: forall c (m :: Type -> Type) a. (Semigroup c, Monad m) => ChronicleT c m a -> ChronicleT c m a
- retcon :: forall c (m :: Type -> Type) a. (Semigroup c, Monad m) => (c -> c) -> ChronicleT c m a -> ChronicleT c m a

# 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 `<>`.

chronicle :: forall (m :: Type -> Type) c a. Monad m => These c a -> ChronicleT c m a Source #

runChronicle :: Chronicle c a -> These c a Source #

# The ChronicleT monad transformer

newtype ChronicleT c (m :: Type -> Type) a Source #

The `ChronicleT` monad transformer.

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

Constructors

ChronicleT |

Fields

- runChronicleT :: m (These c a)

#### Instances

Instances details

(Semigroup c, MonadRWS r w s m) => MonadRWS r w s (ChronicleT c m) Source # |
Instance details Defined in Control.Monad.Trans.Chronicle
(Semigroup c, Monad m) => MonadChronicle c (ChronicleT c m) Source # |

Instance details

Defined in Control.Monad.Chronicle.Class

Methods

dictate :: c -> ChronicleT c m () 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, MonadError e m) => MonadError e (ChronicleT c m) Source # |
Instance details Defined in Control.Monad.Trans.Chronicle Methods throwError :: e -> ChronicleT c m a Source # catchError :: ChronicleT c m a -> (e -> ChronicleT c m a) -> ChronicleT c m a Source #
(Semigroup c, MonadReader r m) => MonadReader r (ChronicleT c m) Source # |
Instance details Defined in Control.Monad.Trans.Chronicle Methods ask :: ChronicleT c m r Source # local :: (r -> r) -> ChronicleT c m a -> ChronicleT c m a Source # reader :: (r -> a) -> ChronicleT c m a Source #
(Semigroup c, MonadState s m) => MonadState s (ChronicleT c m) Source # |
Instance details Defined in Control.Monad.Trans.Chronicle Methods get :: ChronicleT c m s Source # put :: s -> ChronicleT c m () Source # state :: (s -> (a, s)) -> ChronicleT c m a Source #
(Semigroup c, MonadWriter w m) => MonadWriter w (ChronicleT c m) Source # |
Instance details Defined in Control.Monad.Trans.Chronicle Methods writer :: (a, w) -> ChronicleT c m a Source # tell :: w -> ChronicleT c m () Source # listen :: ChronicleT c m a -> ChronicleT c m (a, w) Source # pass :: ChronicleT c m (a, w -> w) -> ChronicleT c m a Source #
Semigroup c => MonadTrans (ChronicleT c) Source # |
Instance details Defined in Control.Monad.Trans.Chronicle Methods lift :: Monad m => m a -> ChronicleT c m a Source #
(Semigroup c, MonadIO m) => MonadIO (ChronicleT c m) Source # |
Instance details Defined in Control.Monad.Trans.Chronicle Methods liftIO :: IO a -> ChronicleT c m a Source #
(Semigroup c, Monoid c, Applicative m, Monad m) => Alternative (ChronicleT c m) Source # |
Instance details Defined in Control.Monad.Trans.Chronicle Methods empty :: ChronicleT c m a Source # (<|>) :: ChronicleT c m a -> ChronicleT c m a -> ChronicleT c m a Source # some :: ChronicleT c m a -> ChronicleT c m [a] Source # many :: ChronicleT c m a -> ChronicleT c m [a] Source #
(Semigroup c, Applicative m) => Applicative (ChronicleT c m) Source # |

Instance details

Defined in Control.Monad.Trans.Chronicle

Methods

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

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

liftA2 :: (a -> b -> c0) -> ChronicleT c m a -> ChronicleT c m b -> ChronicleT c m c0 Source #

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

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

Functor m => Functor (ChronicleT c m) Source # |
Instance details Defined in Control.Monad.Trans.Chronicle Methods fmap :: (a -> b) -> ChronicleT c m a -> ChronicleT c m b Source # (<$) :: a -> ChronicleT c m b -> ChronicleT c m a Source #
(Semigroup c, Monad m) => Monad (ChronicleT c m) Source # |
Instance details Defined in Control.Monad.Trans.Chronicle Methods (>>=) :: ChronicleT c m a -> (a -> ChronicleT c m b) -> ChronicleT c m b Source # (>>) :: ChronicleT c m a -> ChronicleT c m b -> ChronicleT c m b Source # return :: a -> ChronicleT c m a Source #
(Semigroup c, Monoid c, Monad m) => MonadPlus (ChronicleT c m) Source # |
Instance details Defined in Control.Monad.Trans.Chronicle Methods mzero :: ChronicleT c m a Source # mplus :: ChronicleT c m a -> ChronicleT c m a -> ChronicleT c m a Source #
(Semigroup c, MonadFix m) => MonadFix (ChronicleT c m) Source # |
Instance details Defined in Control.Monad.Trans.Chronicle Methods mfix :: (a -> ChronicleT c m a) -> ChronicleT c m a Source #
(Semigroup c, Apply m) => Apply (ChronicleT c m) Source # |
Instance details Defined in Control.Monad.Trans.Chronicle Methods (<.>) :: ChronicleT c m (a -> b) -> ChronicleT c m a -> ChronicleT c m b Source # (.>) :: ChronicleT c m a -> ChronicleT c m b -> ChronicleT c m b Source # (<.) :: ChronicleT c m a -> ChronicleT c m b -> ChronicleT c m a Source # liftF2 :: (a -> b -> c0) -> ChronicleT c m a -> ChronicleT c m b -> ChronicleT c m c0 Source #
(Semigroup c, Apply m, Monad m) => Bind (ChronicleT c m) Source # |
Instance details Defined in Control.Monad.Trans.Chronicle Methods (>>-) :: ChronicleT c m a -> (a -> ChronicleT c m b) -> ChronicleT c m b Source # join :: ChronicleT c m (ChronicleT c m a) -> ChronicleT c m a Source #

# Chronicle operations

dictate :: forall c (m :: Type -> Type). (Semigroup 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 :: forall c (m :: Type -> Type) a. (Semigroup 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 :: forall c (m :: Type -> Type) a. (Semigroup 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 :: forall c (m :: Type -> Type) a. (Semigroup 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 :: forall c (m :: Type -> Type) a. (Semigroup 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 :: forall c (m :: Type -> Type) a. (Semigroup 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.