packages feed

monadLib 3.9 → 3.10

raw patch · 4 files changed

+104/−81 lines, 4 filesdep ~basePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base

API changes (from Hackage documentation)

- MonadLib.Derive: derive_fail :: Monad m => Iso m n -> String -> n a
+ MonadLib.Derive: derive_fail :: MonadFail m => Iso m n -> String -> n a

Files

monadLib.cabal view
@@ -1,5 +1,5 @@ Name:           monadLib-Version:        3.9+Version:        3.10 License:        BSD3 License-file:   LICENSE Author:         Iavor S. Diatchki
src/MonadLib.hs view
@@ -49,27 +49,15 @@   module Control.Monad ) where -#if __GLASGOW_HASKELL__ < 800-import Data.Monoid-#endif- import Control.Applicative import Control.Monad import Control.Monad.Fix import Control.Monad.ST (ST)-import qualified Control.Exception as IO (throwIO,try)-#ifdef USE_BASE3-import qualified Control.Exception as IO (Exception)-#else-import qualified Control.Exception as IO (SomeException)-#endif+import qualified Control.Exception as IO (throwIO,try,SomeException) import System.Exit(ExitCode,exitWith) import Data.Kind(Type) import Prelude hiding (Ordering(..))-#if __GLASGOW_HASKELL__ >= 800 import qualified Control.Monad.Fail as MF-import Control.Monad.Fail(MonadFail)-#endif   -- $Types@@ -261,11 +249,13 @@ t_return   :: (MonadT t, Monad m) => a -> t m a t_return x  = lift (return x) -t_fail     :: (MonadT t, Monad m) => String -> t m a-t_fail x    = lift (fail x)+t_fail     :: (MonadT t, MF.MonadFail m) => String -> t m a+t_fail x    = lift (MF.fail x) -t_fail'    :: (MonadT t, MonadFail m) => String -> t m a-t_fail' x   = lift (MF.fail x)+#if !MIN_VERSION_base(4,11,0)+t_oldfail  :: (MonadT t, Monad m) => String -> t m a+t_oldfail x = lift (fail x)+#endif  t_mzero    :: (MonadT t, MonadPlus m) => t m a t_mzero     = lift mzero@@ -313,64 +303,82 @@   instance Monad Id where-  return x = I x-  fail x   = error x   m >>= k  = k (runId m) +#if !MIN_VERSION_base(4,11,0)+  fail = error+#endif+ instance Monad Lift where-  return x  = L x-  fail x    = error x   L x >>= k = k x     -- Note: the pattern is important here                       -- because it makes things strict +#if !MIN_VERSION_base(4,11,0)+  fail = error+#endif + -- Note: None of the transformers make essential use of the 'fail' method. -- Instead, they delegate its behavior to the underlying monad.  instance (Monad m) => Monad (IdT m) where-  return  = t_return-  fail    = t_fail   m >>= k = IT (runIdT m >>= (runIdT . k)) +#if !MIN_VERSION_base(4,11,0)+  fail = t_oldfail+#endif+ instance (Monad m) => Monad (ReaderT i m) where-  return  = t_return-  fail    = t_fail   m >>= k = R (\r -> runReaderT r m >>= \a -> runReaderT r (k a)) +#if !MIN_VERSION_base(4,11,0)+  fail = t_oldfail+#endif+ instance (Monad m) => Monad (StateT i m) where-  return  = t_return-  fail    = t_fail   m >>= k = S (\s -> runStateT s m >>= \ ~(a,s') -> runStateT s' (k a)) +#if !MIN_VERSION_base(4,11,0)+  fail = t_oldfail+#endif+ instance (Monad m,Monoid i) => Monad (WriterT i m) where-  return  = t_return-  fail    = t_fail   m >>= k = W $ unW m     >>= \ ~(P a w1) ->                 unW (k a) >>= \ ~(P b w2) ->                 return (P b (mappend w1 w2)) +#if !MIN_VERSION_base(4,11,0)+  fail = t_oldfail+#endif+ instance (Monad m) => Monad (ExceptionT i m) where-  return  = t_return-  fail    = t_fail   m >>= k = X $ runExceptionT m >>= \e ->                 case e of                   Left x  -> return (Left x)                   Right a -> runExceptionT (k a) +#if !MIN_VERSION_base(4,11,0)+  fail = t_oldfail+#endif+ instance (Monad m) => Monad (ChoiceT m) where-  return x  = Answer x-  fail x    = lift (fail x)    Answer a  >>= k     = k a   NoAnswer >>= _      = NoAnswer   Choice m1 m2 >>= k  = Choice (m1 >>= k) (m2 >>= k)   ChoiceEff m >>= k   = ChoiceEff (liftM (>>= k) m) +#if !MIN_VERSION_base(4,11,0)+  fail = t_oldfail+#endif+ instance (Monad m) => Monad (ContT i m) where-  return  = t_return-  fail    = t_fail   m >>= k = C $ \c -> runContT (\a -> runContT c (k a)) m +#if !MIN_VERSION_base(4,11,0)+  fail = t_oldfail+#endif+ instance                       Functor Id               where fmap = liftM instance                       Functor Lift             where fmap = liftM instance (Monad m)          => Functor (IdT          m) where fmap = liftM@@ -386,17 +394,17 @@ -- NOTE: It may be possible to make these more general -- (i.e., have Applicative, or even Functor transformers) -instance              Applicative Id            where (<*>) = ap; pure = return-instance              Applicative Lift          where (<*>) = ap; pure = return-instance (Monad m) => Applicative (IdT m)       where (<*>) = ap; pure = return-instance (Monad m) => Applicative (ReaderT i m) where (<*>) = ap; pure = return-instance (Monad m) => Applicative (StateT i m)  where (<*>) = ap; pure = return+instance              Applicative Id            where (<*>) = ap; pure x = I x+instance              Applicative Lift          where (<*>) = ap; pure x = L x+instance (Monad m) => Applicative (IdT m)       where (<*>) = ap; pure = t_return+instance (Monad m) => Applicative (ReaderT i m) where (<*>) = ap; pure = t_return+instance (Monad m) => Applicative (StateT i m)  where (<*>) = ap; pure = t_return instance (Monad m,Monoid i)-                   => Applicative (WriterT i m) where (<*>) = ap; pure = return+                   => Applicative (WriterT i m) where (<*>) = ap; pure = t_return instance (Monad m) => Applicative (ExceptionT i m)-                                                where (<*>) = ap; pure = return-instance (Monad m) => Applicative (ChoiceT m)   where (<*>) = ap; pure = return-instance (Monad m) => Applicative (ContT i m)   where (<*>) = ap; pure = return+                                                where (<*>) = ap; pure = t_return+instance (Monad m) => Applicative (ChoiceT m)   where (<*>) = ap; pure = Answer+instance (Monad m) => Applicative (ContT i m)   where (<*>) = ap; pure = t_return  instance (MonadPlus m)            => Alternative (IdT m)           where (<|>) = mplus; empty = mzero@@ -689,13 +697,8 @@   -- successful computations are tagged with "Right".   try :: m a -> m (Either i a) -#ifdef USE_BASE3-instance RunExceptionM IO IO.Exception where-  try = IO.try-#else instance RunExceptionM IO IO.SomeException where   try = IO.try-#endif  instance (Monad m) => RunExceptionM (ExceptionT i m) i where   try m = lift (runExceptionT m)@@ -857,13 +860,11 @@   WithBase b (f ': fs)  = f (WithBase b fs)  -#if __GLASGOW_HASKELL__ >= 800-instance MonadFail m => MonadFail (IdT          m) where fail = t_fail'-instance MonadFail m => MonadFail (ReaderT    i m) where fail = t_fail'-instance (Monoid i, MonadFail m)-                     => MonadFail (WriterT    i m) where fail = t_fail'-instance MonadFail m => MonadFail (StateT     i m) where fail = t_fail'-instance MonadFail m => MonadFail (ExceptionT i m) where fail = t_fail'-instance MonadFail m => MonadFail (ChoiceT      m) where fail = t_fail'-instance MonadFail m => MonadFail (ContT      i m) where fail = t_fail'-#endif+instance MF.MonadFail m => MF.MonadFail (IdT          m) where fail = t_fail+instance MF.MonadFail m => MF.MonadFail (ReaderT    i m) where fail = t_fail+instance (Monoid i, MF.MonadFail m)+                        => MF.MonadFail (WriterT    i m) where fail = t_fail+instance MF.MonadFail m => MF.MonadFail (StateT     i m) where fail = t_fail+instance MF.MonadFail m => MF.MonadFail (ExceptionT i m) where fail = t_fail+instance MF.MonadFail m => MF.MonadFail (ChoiceT      m) where fail = t_fail+instance MF.MonadFail m => MF.MonadFail (ContT      i m) where fail = t_fail
src/MonadLib/Derive.hs view
@@ -32,6 +32,7 @@ import Control.Applicative import Control.Monad.Fix import Prelude hiding (Ordering(..))+import Control.Monad.Fail as MF  -- | An isomorphism between (usually) monads. -- Typically the constructor and selector of a newtype delcaration.@@ -66,8 +67,8 @@ derive_bind :: (Monad m) => Iso m n -> n a -> (a -> n b) -> n b derive_bind iso m k = close iso ((open iso m) >>= \x -> open iso (k x)) -derive_fail :: (Monad m) => Iso m n -> String -> n a-derive_fail iso a = close iso (fail a)+derive_fail :: (MF.MonadFail m) => Iso m n -> String -> n a+derive_fail iso a = close iso (MF.fail a)  -- | Derive the implementation of 'mfix' from 'MonadFix'. derive_mfix :: (MonadFix m) => Iso m n -> (a -> n a) -> n a
src/MonadLib/Monads.hs view
@@ -17,10 +17,6 @@ import MonadLib import MonadLib.Derive import Control.Monad.Fix-#if __GLASGOW_HASKELL__ < 800-import Data.Monoid-import Control.Applicative-#endif  newtype Reader    i a = R' { unR :: ReaderT    i Id a } newtype Writer    i a = W' { unW :: WriterT    i Id a }@@ -47,41 +43,66 @@ instance               BaseM (Cont      i) (Cont      i) where inBase = id  instance Monad (Reader i) where-  return  = derive_return iso_R-  fail    = derive_fail iso_R   (>>=)   = derive_bind iso_R +#if !MIN_VERSION_base(4,11,0)+  fail = error+#endif+ instance (Monoid i) => Monad (Writer i) where-  return  = derive_return iso_W-  fail    = derive_fail iso_W   (>>=)   = derive_bind iso_W +#if !MIN_VERSION_base(4,11,0)+  fail = error+#endif+ instance Monad (State i) where-  return  = derive_return iso_S-  fail    = derive_fail iso_S   (>>=)   = derive_bind iso_S +#if !MIN_VERSION_base(4,11,0)+  fail = error+#endif++ instance Monad (Exception i) where-  return  = derive_return iso_X-  fail    = derive_fail iso_X   (>>=)   = derive_bind iso_X +#if !MIN_VERSION_base(4,11,0)+  fail = error+#endif+ instance Monad (Cont i) where-  return  = derive_return iso_C-  fail    = derive_fail iso_C   (>>=)   = derive_bind iso_C +#if !MIN_VERSION_base(4,11,0)+  fail = error+#endif+ instance               Functor (Reader    i) where fmap = derive_fmap iso_R instance (Monoid i) => Functor (Writer    i) where fmap = derive_fmap iso_W instance               Functor (State     i) where fmap = derive_fmap iso_S instance               Functor (Exception i) where fmap = derive_fmap iso_X instance               Functor (Cont      i) where fmap = derive_fmap iso_C -instance               Applicative (Reader    i) where pure = return; (<*>) = ap-instance (Monoid i) => Applicative (Writer    i) where pure = return; (<*>) = ap-instance               Applicative (State     i) where pure = return; (<*>) = ap-instance               Applicative (Exception i) where pure = return; (<*>) = ap-instance               Applicative (Cont      i) where pure = return; (<*>) = ap+instance Applicative (Reader i) where+  pure = derive_return iso_R+  (<*>) = ap++instance (Monoid i) => Applicative (Writer i) where+  pure = derive_return iso_W+  (<*>) = ap++instance Applicative (State i) where+  pure = derive_return iso_S+  (<*>) = ap++instance Applicative (Exception i) where+  pure = derive_return iso_X+  (<*>) = ap++instance Applicative (Cont i) where+  pure = derive_return iso_C+  (<*>) = ap  instance               MonadFix (Reader    i) where mfix = derive_mfix iso_R instance (Monoid i) => MonadFix (Writer    i) where mfix = derive_mfix iso_W