monadLib 3.0.0 → 3.1.0
raw patch · 2 files changed
+37/−15 lines, 2 filesnew-uploaderPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ MonadLib: data Lift a
+ MonadLib: instance BaseM Lift Lift
+ MonadLib: instance Functor Lift
+ MonadLib: instance Monad Lift
+ MonadLib: instance MonadFix Lift
+ MonadLib: runLift :: Lift a -> a
Files
- monadLib.cabal +8/−4
- src/MonadLib.hs +29/−11
monadLib.cabal view
@@ -1,16 +1,20 @@ Name: monadLib-Version: 3.0.0+Version: 3.1.0 License: BSD3+License-file: LICENSE Author: Iavor S. Diatchki Maintainer: diatchki@csee.ogi.edu-Homepage: http://www.csee.ogi.edu/~diacthki/monadLib+Homepage: http://www.csee.ogi.edu/~diatchki/monadLib Category: Monads Synopsis: A collection of monad transformers.+Description: A collection of monad transformers. hs-source-dirs: src Build-Depends: base Extra-source-files: LICENSE README-Exposed-modules: MonadLib Monads+Exposed-modules: + MonadLib+ Monads Extensions: - MultiParamTypeClasses, FunctionalDependencies, PolymorphicComponents + MultiParamTypeClasses, FunctionalDependencies GHC-options: -O2 -W -fallow-undecidable-instances
src/MonadLib.hs view
@@ -5,7 +5,7 @@ module MonadLib ( -- * Types -- $Types- Id, ReaderT, WriterT, StateT, ExceptionT, ContT,+ Id, Lift, ReaderT, WriterT, StateT, ExceptionT, ContT, -- * Lifting -- $Lifting@@ -20,7 +20,7 @@ -- ** Eliminating Effects -- $Execution- runId, runReaderT, runWriterT, runStateT, runExceptionT, runContT, + runId, runLift, runReaderT, runWriterT, runStateT, runExceptionT, runContT, -- ** Nested Execution -- $Nested_Exec@@ -37,7 +37,7 @@ -- | The current version of the library. version :: (Int,Int,Int)-version = (3,0,0)+version = (3,1,0) -- $Types@@ -49,6 +49,9 @@ -- | Computations with no effects. newtype Id a = I a +-- | Computation with no effects (stritc).+data Lift a = L a+ -- | Add support for propagating a context. newtype ReaderT i m a = R (i -> m a) @@ -80,6 +83,10 @@ runId :: Id a -> a runId (I a) = a +-- | Get the result of a pure strict computation.+runLift :: Lift a -> a+runLift (L a) = a+ -- | Execute a reader computation in the given context. runReaderT :: i -> ReaderT i m a -> m a runReaderT i (R m) = m i@@ -137,6 +144,7 @@ instance BaseM Maybe Maybe where inBase = id instance BaseM [] [] where inBase = id instance BaseM Id Id where inBase = id+instance BaseM Lift Lift where inBase = id instance (BaseM m n) => BaseM (ReaderT i m) n where inBase = lift . inBase instance (BaseM m n) => BaseM (StateT i m) n where inBase = lift . inBase@@ -150,6 +158,12 @@ fail x = error x m >>= k = k (runId m) ++instance Monad Lift where+ return x = L x+ fail x = error x+ L x >>= k = k x+ -- For the monad transformers, the definition of 'return' -- is completely determined by the 'lift' operations. @@ -189,6 +203,7 @@ m >>= k = C $ \c -> runContT (\a -> runContT c (k a)) m instance Functor Id where fmap = liftM+instance Functor Lift where fmap = liftM instance (Monad m) => Functor (ReaderT i m) where fmap = liftM instance (Monad m) => Functor (StateT i m) where fmap = liftM instance (Monad m,Monoid i) => Functor (WriterT i m) where fmap = liftM@@ -207,6 +222,9 @@ instance MonadFix Id where mfix f = let m = f (runId m) in m +instance MonadFix Lift where+ mfix f = let m = f (runLift m) in m+ instance (MonadFix m) => MonadFix (ReaderT i m) where mfix f = R $ \r -> mfix (runReaderT r . f) @@ -246,7 +264,7 @@ -- that can be used to define effectful computations. --- | Classifies monads that provide access to a context of type 'i'.+-- | Classifies monads that provide access to a context of type @i@. class (Monad m) => ReaderM m i | m -> i where -- | Get the context. ask :: m i@@ -261,7 +279,7 @@ instance (ReaderM m j) => ReaderM (ContT i m) j where ask = lift ask --- | Classifies monads that can collect values of type 'i'.+-- | Classifies monads that can collect values of type @i@. class (Monad m) => WriterM m i | m -> i where -- | Add a value to the collection. put :: i -> m ()@@ -275,7 +293,7 @@ instance (WriterM m j) => WriterM (ContT i m) j where put = lift . put --- | Classifies monads that propagate a state component of type 'i'.+-- | Classifies monads that propagate a state component of type @i@. class (Monad m) => StateM m i | m -> i where -- | Get the state. get :: m i@@ -300,7 +318,7 @@ set = lift . set --- | Classifies monads that support raising exceptions of type 'i'.+-- | Classifies monads that support raising exceptions of type @i@. class (Monad m) => ExceptionM m i | m -> i where -- | Raise an exception. raise :: i -> m a@@ -345,7 +363,7 @@ -- $Nested_Exec -- -- The following classes define operations that are overloaded--- versions of the 'run' operations. Unlike the 'run' operations,+-- versions of the @run@ operations. Unlike the @run@ operations, -- functions do not change the type of the computation (i.e, they -- do not remove a layer). However, they do not perform any -- side-effects in the corresponding layer. Instead, they execute@@ -439,18 +457,18 @@ -- Some convenient functions for working with continuations. -- | An explicit representation for continuations that store a value.-newtype Label m a = L ((a, Label m a) -> m ())+newtype Label m a = Lab ((a, Label m a) -> m ()) -- | Capture the current continuation. -- This function is like 'return', except that it also captures -- the current continuation. Later we can use 'jump' to go back to -- the continuation with a possibly different value. labelCC :: (ContM m) => a -> m (a, Label m a)-labelCC x = callCC (\k -> return (x, L k))+labelCC x = callCC (\k -> return (x, Lab k)) -- | Change the value passed to a previously captured continuation. jump :: (ContM m) => a -> Label m a -> m b-jump x (L k) = k (x, L k) >> return unreachable+jump x (Lab k) = k (x, Lab k) >> return unreachable where unreachable = error "(bug) jump: unreachable"