monadLib 3.4.6 → 3.5.1
raw patch · 3 files changed
+33/−6 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ MonadLib: abort :: (AbortM m i) => i -> m a
+ MonadLib: class (Monad m) => AbortM m i
+ MonadLib: instance (AbortM m i) => AbortM (ChoiceT m) i
+ MonadLib: instance (AbortM m i) => AbortM (ExceptionT j m) i
+ MonadLib: instance (AbortM m i) => AbortM (IdT m) i
+ MonadLib: instance (AbortM m i) => AbortM (ReaderT j m) i
+ MonadLib: instance (AbortM m i) => AbortM (StateT j m) i
+ MonadLib: instance (AbortM m i, Monoid j) => AbortM (WriterT j m) i
+ MonadLib: instance (Monad m) => AbortM (ContT i m) i
+ MonadLib: instance AbortM IO ExitCode
+ MonadLib.Derive: derive_abort :: (AbortM m i) => Iso m n -> i -> n a
Files
- monadLib.cabal +1/−1
- src/MonadLib.hs +28/−5
- src/MonadLib/Derive.hs +4/−0
monadLib.cabal view
@@ -1,5 +1,5 @@ Name: monadLib-Version: 3.4.6+Version: 3.5.1 License: BSD3 License-file: LICENSE Author: Iavor S. Diatchki
src/MonadLib.hs view
@@ -18,7 +18,7 @@ -- * Effect Classes -- $Effects- ReaderM(..), WriterM(..), StateM(..), ExceptionM(..), ContM(..),+ ReaderM(..), WriterM(..), StateM(..), ExceptionM(..), ContM(..), AbortM(..), Label, labelCC, jump, -- * Execution@@ -45,6 +45,7 @@ import Control.Monad.Fix import Control.Monad.ST (ST) import qualified Control.Exception as IO (throwIO,try,Exception)+import System.Exit(ExitCode,exitWith) import Data.Monoid import Prelude hiding (Ordering(..)) @@ -100,7 +101,7 @@ -- of a computation by translating a computation into an -- equivalent computation in the underlying monad. -- (The exceptions are 'Id' and 'Lift' which are not transformers--- but ordinary monas and so, their run operations simply+-- but ordinary monads and so, their run operations simply -- eliminate the monad.) @@ -159,7 +160,7 @@ findOne :: (Monad m) => ChoiceT m a -> m (Maybe a) findOne m = fmap fst `liftM` runChoiceT m --- | Executie a computation that may return multiple answers,+-- | Execute a computation that may return multiple answers, -- collecting all possible answers. findAll :: (Monad m) => ChoiceT m a -> m [a] findAll m = all_res =<< runChoiceT m@@ -236,6 +237,9 @@ t_raise :: (MonadT t, ExceptionM m i) => i -> t m a t_raise i = lift (raise i)++t_abort :: (MonadT t, AbortM m i) => i -> t m a+t_abort i = lift (abort i) -------------------------------------------------------------------------------- @@ -547,12 +551,11 @@ instance (Monad m) => ContM (ContT i m) where callCC f = C $ \k -> runContT k $ f $ \a -> C $ \_ -> k a - -- $Nested_Exec -- -- The following classes define operations that are overloaded -- versions of the @run@ operations. Unlike the @run@ operations,--- these functions do not change the type of the computation (i.e, they+-- these functions do not change the type of the computation (i.e., they -- do not remove a layer). Instead, they perform the effects in -- a ``separate effect thread''. @@ -636,6 +639,26 @@ where swap _ (Right ~(a,s)) = (Right a,s) swap s (Left e) = (Left e, s) +-- | Classifies monads that support aborting the program and returning+-- a given final result of type 'i'.+class Monad m => AbortM m i where++ -- | Abort the program with the given value as final result.+ abort :: i -> m a++instance Monad m => AbortM (ContT i m) i where+ abort i = C (\_ -> return i)++instance AbortM IO ExitCode where+ abort = exitWith++instance AbortM m i => AbortM (IdT m) i where abort = t_abort+instance AbortM m i => AbortM (ReaderT j m) i where abort = t_abort+instance (AbortM m i,Monoid j)+ => AbortM (WriterT j m) i where abort = t_abort+instance AbortM m i => AbortM (StateT j m) i where abort = t_abort+instance AbortM m i => AbortM (ExceptionT j m) i where abort = t_abort+instance AbortM m i => AbortM (ChoiceT m) i where abort = t_abort -------------------------------------------------------------------------------- -- Some convenient functions for working with continuations.
src/MonadLib/Derive.hs view
@@ -5,6 +5,7 @@ module MonadLib.Derive ( Iso(Iso), derive_fmap, derive_return, derive_bind, derive_fail, derive_mfix, derive_ask, derive_put, derive_get, derive_set, derive_raise, derive_callCC,+ derive_abort, derive_local, derive_collect, derive_try, derive_mzero, derive_mplus, derive_lift, derive_inBase,@@ -63,6 +64,9 @@ -- | Derive the implementation of 'callCC' from 'ContM'. derive_callCC :: (ContM m) => Iso m n -> ((a -> n b) -> n a) -> n a derive_callCC iso f = close iso (callCC (open iso . f . (close iso .)))++derive_abort :: (AbortM m i) => Iso m n -> i -> n a+derive_abort iso i = close iso (abort i) -- | Derive the implementation of 'local' from 'RunReaderM'. derive_local :: (RunReaderM m i) => Iso m n -> i -> n a -> n a