monadLib 3.5.2 → 3.6
raw patch · 3 files changed
+46/−1 lines, 3 files
Files
- monadLib.cabal +1/−1
- src/MonadLib.hs +40/−0
- src/MonadLib/Derive.hs +5/−0
monadLib.cabal view
@@ -1,5 +1,5 @@ Name: monadLib-Version: 3.5.2+Version: 3.6 License: BSD3 License-file: LICENSE Author: Iavor S. Diatchki
src/MonadLib.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP, MultiParamTypeClasses, FunctionalDependencies,+ UndecidableInstances, FlexibleInstances #-} {-| This library provides a collection of monad transformers that can be combined to produce various monads. -}@@ -28,6 +30,7 @@ runIdT, runReaderT, runWriterT, runStateT, runExceptionT, runContT, runChoiceT, findOne, findAll,+ RunM(..), -- ** Nested Execution -- $Nested_Exec@@ -181,7 +184,41 @@ runContT i (C m) = m i +-- | Generalized running.+class Monad m => RunM m a r | m a -> r where+ runM :: m a -> r +instance RunM Id a a where+ runM = runId++instance RunM Lift a a where+ runM = runLift++instance RunM IO a (IO a) where+ runM = id++instance RunM m a r => RunM (IdT m) a r where+ runM = runM . runIdT++instance RunM m a r => RunM (ReaderT i m) a (i -> r) where+ runM m i = runM (runReaderT i m)++instance (Monoid i, RunM m (a,i) r) => RunM (WriterT i m) a r where+ runM = runM . runWriterT++instance RunM m (a,i) r => RunM (StateT i m) a (i -> r) where+ runM m i = runM (runStateT i m)++instance RunM m (Either i a) r => RunM (ExceptionT i m) a r where+ runM = runM . runExceptionT++instance RunM m i r => RunM (ContT i m) a ((a -> m i) -> r) where+ runM m k = runM (runContT k m)++instance RunM m (Maybe (a,ChoiceT m a)) r => RunM (ChoiceT m) a r where+ runM = runM . runChoiceT++ -- $Lifting -- -- The following operations allow us to promote computations@@ -583,6 +620,9 @@ local i (S m) = S (local i . m) instance (RunReaderM m j) => RunReaderM (ExceptionT i m) j where local i (X m) = X (local i m)++instance (RunReaderM m j) => RunReaderM (ContT i m) j where+ local i (C m) = C (local i . m) -- | Classifies monads that support collecting the output of -- a sub-computation.
src/MonadLib/Derive.hs view
@@ -8,6 +8,7 @@ derive_local, derive_collect, derive_try, derive_mzero, derive_mplus, derive_lift, derive_inBase,+ derive_runM, ) where @@ -94,3 +95,7 @@ -- | Derive the implementation of 'inBase' from 'BaseM'. derive_inBase :: (BaseM m x) => Iso m n -> x a -> n a derive_inBase iso m = close iso (inBase m)++-- | Derive the implementation of the 'runM' function from 'RunM'.+derive_runM :: (RunM m a r) => Iso m n -> n a -> r+derive_runM iso m = runM (open iso m)