monad-chronicle 1 → 1.0.0.1
raw patch · 4 files changed
+42/−32 lines, 4 filesdep ~basedep ~semigroupsdep ~these
Dependency ranges changed: base, semigroups, these, transformers-compat
Files
- monad-chronicle.cabal +14/−4
- src/Control/Monad/Chronicle.hs +1/−1
- src/Control/Monad/Chronicle/Class.hs +1/−1
- src/Control/Monad/Trans/Chronicle.hs +26/−26
monad-chronicle.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: monad-chronicle-version: 1+version: 1.0.0.1 synopsis: These as a transformer, ChronicleT homepage: https://github.com/isomorphism/these license: BSD3@@ -16,7 +16,17 @@ transformer bells and whistles. tested-with:- GHC ==7.4.2 || ==7.6.3 || ==7.8.4 || ==7.10.3 || ==8.0.2 || ==8.2.2 || ==8.4.4 || ==8.6.5 || ==8.8.1+ GHC ==7.4.2+ || ==7.6.3+ || ==7.8.4+ || ==7.10.3+ || ==8.0.2+ || ==8.2.2+ || ==8.4.4+ || ==8.6.5+ || ==8.8.3+ || ==8.10.1+ , GHCJS ==8.4 source-repository head type: git@@ -42,11 +52,11 @@ -- ghc boot libs build-depends:- base >=4.5.1.0 && <4.13+ base >=4.5.1.0 && <4.15 , mtl >=2.1.3 && <2.3 , transformers >=0.3.0.0 && <0.6 - build-depends: these >=1 && <1.1+ build-depends: these >=1 && <1.2 -- other dependencies build-depends:
src/Control/Monad/Chronicle.hs view
@@ -14,4 +14,4 @@ ) where import Control.Monad.Chronicle.Class-import Control.Monad.Trans.Chronicle (Chronicle, runChronicle, ChronicleT (..))+import Control.Monad.Trans.Chronicle (Chronicle, ChronicleT (..), runChronicle)
src/Control/Monad/Chronicle/Class.hs view
@@ -1,6 +1,6 @@-{-# LANGUAGE Trustworthy #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FunctionalDependencies #-}+{-# LANGUAGE Trustworthy #-} {-# LANGUAGE UndecidableInstances #-} {-# OPTIONS_GHC -fno-warn-warnings-deprecations #-} -- for the ErrorT instances -----------------------------------------------------------------------------
src/Control/Monad/Trans/Chronicle.hs view
@@ -1,19 +1,19 @@-{-# LANGUAGE Trustworthy #-}-{-# LANGUAGE CPP #-}-{-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE UndecidableInstances #-} ----------------------------------------------------------------------------- -- | Module : Control.Monad.Chronicle ----- Hybrid error/writer monad class that allows both accumulating outputs and +-- 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. +-- The expected use case is for computations with a notion of fatal vs. -- non-fatal errors. ------------------------------------------------------------------------------module Control.Monad.Trans.Chronicle ( +module Control.Monad.Trans.Chronicle ( -- * The Chronicle monad Chronicle, chronicle, runChronicle, -- * The ChronicleT monad transformer@@ -35,13 +35,13 @@ import Control.Monad.Error.Class import Control.Monad.Reader.Class import Control.Monad.RWS.Class-import Prelude import Data.These-import Data.These.Combinators (mapHere)+import Data.These.Combinators (mapHere)+import Prelude #ifdef MIN_VERSION_semigroupoids-import Data.Functor.Apply (Apply(..))-import Data.Functor.Bind (Bind(..))+import Data.Functor.Apply (Apply (..))+import Data.Functor.Bind (Bind (..)) #endif -- --------------------------------------------------------------------------@@ -52,7 +52,7 @@ type Chronicle c = ChronicleT c Identity chronicle :: Monad m => These c a -> ChronicleT c m a-chronicle = ChronicleT . return +chronicle = ChronicleT . return runChronicle :: Chronicle c a -> These c a runChronicle = runIdentity . runChronicleT@@ -69,7 +69,7 @@ #ifdef MIN_VERSION_semigroupoids instance (Semigroup c, Apply m) => Apply (ChronicleT c m) where- ChronicleT f <.> ChronicleT x = ChronicleT ((<.>) <$> f <.> x)+ ChronicleT f <.> ChronicleT x = ChronicleT ((<*>) <$> f <.> x) instance (Semigroup c, Apply m, Monad m) => Bind (ChronicleT c m) where (>>-) = (>>=)@@ -81,9 +81,9 @@ instance (Semigroup c, Monad m) => Monad (ChronicleT c m) where return = ChronicleT . return . return- m >>= k = ChronicleT $ + m >>= k = ChronicleT $ do cx <- runChronicleT m- case cx of + case cx of This a -> return (This a) That x -> runChronicleT (k x) These a x -> do cy <- runChronicleT (k x)@@ -137,8 +137,8 @@ That x -> That (x, w) These c x -> These c (x, w) pass (ChronicleT m) = ChronicleT $ do- pass $ these (\c -> (This c, id)) - (\(x, f) -> (That x, f)) + pass $ these (\c -> (This c, id))+ (\(x, f) -> (That x, f)) (\c (x, f) -> (These c x, f)) `liftM` m writer = lift . writer @@ -150,7 +150,7 @@ -- | @'dictate' c@ is an action that records the output @c@.--- +-- -- Equivalent to 'tell' for the 'Writer' monad. dictate :: (Semigroup c, Monad m) => c -> ChronicleT c m () dictate c = ChronicleT $ return (These c ())@@ -159,13 +159,13 @@ -- @'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 +-- branch a @case@, or similar scenarios when there is no meaningful -- result but a placeholder of sorts is needed in order to continue. disclose :: (Default a, Semigroup c, Monad m) => c -> ChronicleT c m a disclose c = dictate c >> return def -- | @'confess' c@ is an action that ends with a final output @c@.--- +-- -- Equivalent to 'throwError' for the 'Error' monad. confess :: (Semigroup c, Monad m) => c -> ChronicleT c m a confess c = ChronicleT $ return (This c)@@ -174,11 +174,11 @@ -- 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 +-- 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). memento :: (Semigroup c, Monad m) => ChronicleT c m a -> ChronicleT c m (Either c a)-memento m = ChronicleT $ +memento m = ChronicleT $ do cx <- runChronicleT m return $ case cx of This a -> That (Left a)@@ -186,10 +186,10 @@ These a x -> These a (Right x) -- | @'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 +-- record it had. The default value @x@ will be used if @m@ ended via -- 'confess'. absolve :: (Semigroup c, Monad m) => a -> ChronicleT c m a -> ChronicleT c m a-absolve x m = ChronicleT $ +absolve x m = ChronicleT $ do cy <- runChronicleT m return $ case cy of This _ -> That x@@ -203,7 +203,7 @@ -- -- This can be seen as converting non-fatal errors into fatal ones. condemn :: (Semigroup c, Monad m) => ChronicleT c m a -> ChronicleT c m a-condemn (ChronicleT m) = ChronicleT $ do +condemn (ChronicleT m) = ChronicleT $ do m' <- m return $ case m' of This x -> This x@@ -213,7 +213,7 @@ -- | @'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. retcon :: (Semigroup c, Monad m) => (c -> c) -> ChronicleT c m a -> ChronicleT c m a retcon f m = ChronicleT $ mapHere f `liftM` runChronicleT m