Permalink
Browse files

2.1 release candidate

  • Loading branch information...
1 parent 6514546 commit fce5986447749625708aced15c7525e4afddd561 @ekmett committed Apr 8, 2012
@@ -69,7 +69,7 @@ import Control.Monad.Trans.Writer.Strict as StrictWriter
import Control.Monad
import Data.Monoid
-class (Monad m) => MonadCont m where
+class Monad m => MonadCont m where
{- | @callCC@ (call-with-current-continuation)
calls a function with the current continuation as its argument.
Provides an escape continuation mechanism for use with Continuation monads.
@@ -99,16 +99,16 @@ instance MonadCont (ContT r m) where
instance (Error e, MonadCont m) => MonadCont (ErrorT e m) where
callCC = Error.liftCallCC callCC
-instance (MonadCont m) => MonadCont (IdentityT m) where
+instance MonadCont m => MonadCont (IdentityT m) where
callCC = Identity.liftCallCC callCC
-instance (MonadCont m) => MonadCont (ListT m) where
+instance MonadCont m => MonadCont (ListT m) where
callCC = List.liftCallCC callCC
-instance (MonadCont m) => MonadCont (MaybeT m) where
+instance MonadCont m => MonadCont (MaybeT m) where
callCC = Maybe.liftCallCC callCC
-instance (MonadCont m) => MonadCont (ReaderT r m) where
+instance MonadCont m => MonadCont (ReaderT r m) where
callCC = Reader.liftCallCC callCC
instance (Monoid w, MonadCont m) => MonadCont (LazyRWS.RWST r w s m) where
@@ -117,10 +117,10 @@ instance (Monoid w, MonadCont m) => MonadCont (LazyRWS.RWST r w s m) where
instance (Monoid w, MonadCont m) => MonadCont (StrictRWS.RWST r w s m) where
callCC = StrictRWS.liftCallCC' callCC
-instance (MonadCont m) => MonadCont (LazyState.StateT s m) where
+instance MonadCont m => MonadCont (LazyState.StateT s m) where
callCC = LazyState.liftCallCC' callCC
-instance (MonadCont m) => MonadCont (StrictState.StateT s m) where
+instance MonadCont m => MonadCont (StrictState.StateT s m) where
callCC = StrictState.liftCallCC' callCC
instance (Monoid w, MonadCont m) => MonadCont (LazyWriter.WriterT w m) where
@@ -95,7 +95,7 @@ instance MonadError IOException IO where
-- ---------------------------------------------------------------------------
-- Our parameterizable error monad
-instance (Error e) => MonadError e (Either e) where
+instance Error e => MonadError e (Either e) where
throwError = Left
Left l `catchError` h = h l
Right r `catchError` _ = Right r
@@ -110,19 +110,19 @@ instance (Monad m, Error e) => MonadError e (ErrorT e m) where
-- All of these instances need UndecidableInstances,
-- because they do not satisfy the coverage condition.
-instance (MonadError e m) => MonadError e (IdentityT m) where
+instance MonadError e m => MonadError e (IdentityT m) where
throwError = lift . throwError
catchError = Identity.liftCatch catchError
-instance (MonadError e m) => MonadError e (ListT m) where
+instance MonadError e m => MonadError e (ListT m) where
throwError = lift . throwError
catchError = List.liftCatch catchError
-instance (MonadError e m) => MonadError e (MaybeT m) where
+instance MonadError e m => MonadError e (MaybeT m) where
throwError = lift . throwError
catchError = Maybe.liftCatch catchError
-instance (MonadError e m) => MonadError e (ReaderT r m) where
+instance MonadError e m => MonadError e (ReaderT r m) where
throwError = lift . throwError
catchError = Reader.liftCatch catchError
@@ -134,11 +134,11 @@ instance (Monoid w, MonadError e m) => MonadError e (StrictRWS.RWST r w s m) whe
throwError = lift . throwError
catchError = StrictRWS.liftCatch catchError
-instance (MonadError e m) => MonadError e (LazyState.StateT s m) where
+instance MonadError e m => MonadError e (LazyState.StateT s m) where
throwError = lift . throwError
catchError = LazyState.liftCatch catchError
-instance (MonadError e m) => MonadError e (StrictState.StateT s m) where
+instance MonadError e m => MonadError e (StrictState.StateT s m) where
throwError = lift . throwError
catchError = StrictState.liftCatch catchError
View
@@ -21,7 +21,7 @@
-----------------------------------------------------------------------------
module Control.Monad.RWS.Class (
- MonadRWS,
+ MonadRWS(..),
module Control.Monad.Reader.Class,
module Control.Monad.State.Class,
module Control.Monad.Writer.Class,
@@ -31,6 +31,7 @@ import Control.Monad.Reader.Class
import Control.Monad.State.Class
import Control.Monad.Writer.Class
+import Control.Monad.Trans.Class
import Control.Monad.Trans.Error(Error, ErrorT)
import Control.Monad.Trans.Maybe(MaybeT)
import Control.Monad.Trans.Identity(IdentityT)
@@ -43,14 +44,15 @@ class (Monoid w, MonadReader r m, MonadWriter w m, MonadState s m)
=> MonadRWS r w s m | m -> r, m -> w, m -> s
instance (Monoid w, Monad m) => MonadRWS r w s (Lazy.RWST r w s m)
+
instance (Monoid w, Monad m) => MonadRWS r w s (Strict.RWST r w s m)
---------------------------------------------------------------------------
-- Instances for other mtl transformers
--
-- All of these instances need UndecidableInstances,
-- because they do not satisfy the coverage condition.
-
+
instance (Error e, MonadRWS r w s m) => MonadRWS r w s (ErrorT e m)
-instance (MonadRWS r w s m) => MonadRWS r w s (IdentityT m)
-instance (MonadRWS r w s m) => MonadRWS r w s (MaybeT m)
+instance MonadRWS r w s m => MonadRWS r w s (IdentityT m)
+instance MonadRWS r w s m => MonadRWS r w s (MaybeT m)
View
@@ -41,7 +41,6 @@ module Control.Monad.Reader (
asks,
-- * The Reader monad
Reader,
- reader,
runReader,
mapReader,
withReader,
@@ -65,7 +64,7 @@ module Control.Monad.Reader (
import Control.Monad.Reader.Class
import Control.Monad.Trans.Reader (
- Reader, reader, runReader, mapReader, withReader,
+ Reader, runReader, mapReader, withReader,
ReaderT(..), mapReaderT, withReaderT)
import Control.Monad.Trans
@@ -48,9 +48,9 @@ import Control.Monad.Trans.Identity
import Control.Monad.Trans.List
import Control.Monad.Trans.Maybe
import Control.Monad.Trans.Reader (ReaderT)
-import qualified Control.Monad.Trans.Reader as ReaderT (ask, local)
-import qualified Control.Monad.Trans.RWS.Lazy as LazyRWS (RWST, ask, local)
-import qualified Control.Monad.Trans.RWS.Strict as StrictRWS (RWST, ask, local)
+import qualified Control.Monad.Trans.Reader as ReaderT (ask, local, reader)
+import qualified Control.Monad.Trans.RWS.Lazy as LazyRWS (RWST, ask, local, reader)
+import qualified Control.Monad.Trans.RWS.Strict as StrictRWS (RWST, ask, local, reader)
import Control.Monad.Trans.State.Lazy as Lazy
import Control.Monad.Trans.State.Strict as Strict
import Control.Monad.Trans.Writer.Lazy as Lazy
@@ -67,80 +67,98 @@ import Data.Monoid
-- | See examples in "Control.Monad.Reader".
-- Note, the partially applied function type @(->) r@ is a simple reader monad.
-- See the @instance@ declaration below.
-class (Monad m) => MonadReader r m | m -> r where
+class Monad m => MonadReader r m | m -> r where
-- | Retrieves the monad environment.
ask :: m r
-- | Executes a computation in a modified environment.
- local :: (r -> r) -- ^ The function to modify the environment.
- -> m a -- ^ @Reader@ to run in the modified environment.
+ local :: (r -> r) -- ^ The function to modify the environment.
+ -> m a -- ^ @Reader@ to run in the modified environment.
-> m a
+ -- | Retrieves a function of the current environment.
+ reader :: (r -> a) -- ^ The selector function to apply to the environment.
+ -> m a
+ reader f = do
+ r <- ask
+ return (f r)
+
-- | Retrieves a function of the current environment.
-asks :: (MonadReader r m)
- => (r -> a) -- ^ The selector function to apply to the environment.
+asks :: MonadReader r m
+ => (r -> a) -- ^ The selector function to apply to the environment.
-> m a
-asks f = do
- r <- ask
- return (f r)
+asks = reader
-- ----------------------------------------------------------------------------
-- The partially applied function type is a simple reader monad
instance MonadReader r ((->) r) where
ask = id
local f m = m . f
+ reader = id
-instance (Monad m) => MonadReader r (ReaderT r m) where
+instance Monad m => MonadReader r (ReaderT r m) where
ask = ReaderT.ask
local = ReaderT.local
+ reader = ReaderT.reader
instance (Monad m, Monoid w) => MonadReader r (LazyRWS.RWST r w s m) where
ask = LazyRWS.ask
local = LazyRWS.local
+ reader = LazyRWS.reader
instance (Monad m, Monoid w) => MonadReader r (StrictRWS.RWST r w s m) where
ask = StrictRWS.ask
local = StrictRWS.local
+ reader = StrictRWS.reader
-- ---------------------------------------------------------------------------
-- Instances for other mtl transformers
--
-- All of these instances need UndecidableInstances,
-- because they do not satisfy the coverage condition.
-instance (MonadReader r' m) => MonadReader r' (ContT r m) where
+instance MonadReader r' m => MonadReader r' (ContT r m) where
ask = lift ask
local = Cont.liftLocal ask local
+ reader = lift . reader
instance (Error e, MonadReader r m) => MonadReader r (ErrorT e m) where
ask = lift ask
local = mapErrorT . local
+ reader = lift . reader
-instance (MonadReader r m) => MonadReader r (IdentityT m) where
+instance MonadReader r m => MonadReader r (IdentityT m) where
ask = lift ask
local = mapIdentityT . local
+ reader = lift . reader
-instance (MonadReader r m) => MonadReader r (ListT m) where
+instance MonadReader r m => MonadReader r (ListT m) where
ask = lift ask
local = mapListT . local
+ reader = lift . reader
-instance (MonadReader r m) => MonadReader r (MaybeT m) where
+instance MonadReader r m => MonadReader r (MaybeT m) where
ask = lift ask
local = mapMaybeT . local
+ reader = lift . reader
-instance (MonadReader r m) => MonadReader r (Lazy.StateT s m) where
+instance MonadReader r m => MonadReader r (Lazy.StateT s m) where
ask = lift ask
local = Lazy.mapStateT . local
+ reader = lift . reader
-instance (MonadReader r m) => MonadReader r (Strict.StateT s m) where
+instance MonadReader r m => MonadReader r (Strict.StateT s m) where
ask = lift ask
local = Strict.mapStateT . local
+ reader = lift . reader
instance (Monoid w, MonadReader r m) => MonadReader r (Lazy.WriterT w m) where
ask = lift ask
local = Lazy.mapWriterT . local
+ reader = lift . reader
instance (Monoid w, MonadReader r m) => MonadReader r (Strict.WriterT w m) where
ask = lift ask
local = Strict.mapWriterT . local
+ reader = lift . reader
Oops, something went wrong.

0 comments on commit fce5986

Please sign in to comment.