Safe Haskell | None |
---|---|
Language | Haskell98 |
The ChronicleT
monad, a hybrid error/writer monad that allows
both accumulating outputs and aborting computation with a final
output.
Synopsis
- class Monad m => MonadChronicle c m | m -> c where
- type Chronicle c = ChronicleT c Identity
- runChronicle :: Chronicle c a -> These c a
- newtype ChronicleT c m a = ChronicleT {
- runChronicleT :: m (These c a)
- class Semigroup a => Monoid a where
- module Control.Monad
- module Control.Monad.Trans
Type class for Chronicle-style monads
class Monad m => MonadChronicle c m | m -> c where Source #
disclose :: Default a => c -> m a Source #
is an action that records the output disclose
cc
and returns a
value.Default
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.
is an action that ends with a final record confess
cc
.
Equivalent to throwError
for the Error
monad.
memento :: m a -> m (Either c a) Source #
is an action that executes the action memento
mm
, 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 #
is an action that executes the action absolve
x mm
and discards any
record it had. The default value x
will be used if m
ended via
confess
.
condemn :: m a -> m a Source #
is an action that executes the action condemn
mm
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 #
is an action that executes the action retcon
f mm
and applies the
function f
to its output, leaving the return value unchanged.
chronicle :: These c a -> m a Source #
lifts a plain 'These c a' value into a chronicle
mMonadChronicle
instance.
Instances
The ChronicleT monad transformer
type Chronicle c = ChronicleT c Identity Source #
runChronicle :: Chronicle c a -> These c 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
.
ChronicleT | |
|
Instances
class Semigroup a => Monoid a where #
The class of monoids (types with an associative binary operation that has an identity). Instances should satisfy the following laws:
x
<>
mempty
= xmempty
<>
x = xx
(<>
(y<>
z) = (x<>
y)<>
zSemigroup
law)mconcat
=foldr
'(<>)'mempty
The method names refer to the monoid of lists under concatenation, but there are many other instances.
Some types can be viewed as a monoid in more than one way,
e.g. both addition and multiplication on numbers.
In such cases we often define newtype
s and make those instances
of Monoid
, e.g. Sum
and Product
.
NOTE: Semigroup
is a superclass of Monoid
since base-4.11.0.0.
Identity of mappend
An associative operation
NOTE: This method is redundant and has the default
implementation
since base-4.11.0.0.mappend
= '(<>)'
Fold a list using the monoid.
For most types, the default definition for mconcat
will be
used, but the function is included in the class definition so
that an optimized version can be provided for specific types.
Instances
module Control.Monad
module Control.Monad.Trans