mtl 2.0.1.1 → 2.1
raw patch · 12 files changed
+137/−87 lines, 12 filesdep ~basedep ~transformersnew-uploader
Dependency ranges changed: base, transformers
Files
- Control/Monad/Cont/Class.hs +7/−7
- Control/Monad/Error/Class.hs +8/−15
- Control/Monad/RWS/Class.hs +6/−4
- Control/Monad/Reader.hs +1/−2
- Control/Monad/Reader/Class.hs +36/−18
- Control/Monad/State/Class.hs +39/−19
- Control/Monad/State/Lazy.hs +1/−2
- Control/Monad/State/Strict.hs +1/−2
- Control/Monad/Writer/Class.hs +29/−11
- Control/Monad/Writer/Lazy.hs +1/−2
- Control/Monad/Writer/Strict.hs +1/−2
- mtl.cabal +7/−3
Control/Monad/Cont/Class.hs view
@@ -69,7 +69,7 @@ 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 (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 (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
Control/Monad/Error/Class.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE CPP, UndecidableInstances #-}+{-# LANGUAGE UndecidableInstances #-} {- | Module : Control.Monad.Error.Class@@ -57,13 +57,6 @@ import Control.Monad.Instances () import Data.Monoid -#if MIN_VERSION_base(4,6,0)-import System.IO.Error (catchIOError)--catch :: IO a -> (IOError -> IO a) -> IO a-catch = catchIOError-#endif- {- | The strategy of combining computations that can throw exceptions by bypassing bound functions@@ -102,7 +95,7 @@ -- --------------------------------------------------------------------------- -- 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@@ -117,19 +110,19 @@ -- 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 @@ -141,11 +134,11 @@ 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
Control/Monad/RWS/Class.hs 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.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,6 +44,7 @@ => 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) ---------------------------------------------------------------------------@@ -50,7 +52,7 @@ -- -- 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)
Control/Monad/Reader.hs view
@@ -41,7 +41,6 @@ asks, -- * The Reader monad Reader,- reader, runReader, mapReader, withReader,@@ -65,7 +64,7 @@ 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
Control/Monad/Reader/Class.hs view
@@ -48,9 +48,9 @@ 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,22 +67,27 @@ -- | 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@@ -90,18 +95,22 @@ 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@@ -109,38 +118,47 @@ -- 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
Control/Monad/State/Class.hs view
@@ -33,10 +33,10 @@ import Control.Monad.Trans.List import Control.Monad.Trans.Maybe import Control.Monad.Trans.Reader-import qualified Control.Monad.Trans.RWS.Lazy as LazyRWS (RWST, get, put)-import qualified Control.Monad.Trans.RWS.Strict as StrictRWS (RWST, get, put)-import qualified Control.Monad.Trans.State.Lazy as Lazy (StateT, get, put)-import qualified Control.Monad.Trans.State.Strict as Strict (StateT, get, put)+import qualified Control.Monad.Trans.RWS.Lazy as LazyRWS (RWST, get, put, state)+import qualified Control.Monad.Trans.RWS.Strict as StrictRWS (RWST, get, put, state)+import qualified Control.Monad.Trans.State.Lazy as Lazy (StateT, get, put, state)+import qualified Control.Monad.Trans.State.Strict as Strict (StateT, get, put, state) import Control.Monad.Trans.Writer.Lazy as Lazy import Control.Monad.Trans.Writer.Strict as Strict @@ -46,12 +46,24 @@ -- --------------------------------------------------------------------------- -class (Monad m) => MonadState s m | m -> s where+-- | Minimal definition is either both of @get@ and @put@ or just @state@+class Monad m => MonadState s m | m -> s where -- | Return the state from the internals of the monad. get :: m s+ get = state (\s -> (s, s))+ -- | Replace the state inside the monad. put :: s -> m ()+ put s = state (\_ -> ((), s)) + -- | Embed a simple state action into the monad.+ state :: (s -> (a, s)) -> m a+ state f = do+ s <- get+ let ~(a, s) = f s+ put s+ return a+ -- | Monadic state transformer. -- -- Maps an old state to a new state inside a state monad.@@ -63,35 +75,35 @@ -- This says that @modify (+1)@ acts over any -- Monad that is a member of the @MonadState@ class, -- with an @Int@ state.--modify :: (MonadState s m) => (s -> s) -> m ()-modify f = do- s <- get- put (f s)+modify :: MonadState s m => (s -> s) -> m ()+modify f = state (\s -> ((), f s)) -- | Gets specific component of the state, using a projection function -- supplied.--gets :: (MonadState s m) => (s -> a) -> m a+gets :: MonadState s m => (s -> a) -> m a gets f = do s <- get return (f s) -instance (Monad m) => MonadState s (Lazy.StateT s m) where+instance Monad m => MonadState s (Lazy.StateT s m) where get = Lazy.get put = Lazy.put+ state = Lazy.state -instance (Monad m) => MonadState s (Strict.StateT s m) where+instance Monad m => MonadState s (Strict.StateT s m) where get = Strict.get put = Strict.put+ state = Strict.state instance (Monad m, Monoid w) => MonadState s (LazyRWS.RWST r w s m) where get = LazyRWS.get put = LazyRWS.put+ state = LazyRWS.state instance (Monad m, Monoid w) => MonadState s (StrictRWS.RWST r w s m) where get = StrictRWS.get put = StrictRWS.put+ state = StrictRWS.state -- --------------------------------------------------------------------------- -- Instances for other mtl transformers@@ -99,34 +111,42 @@ -- All of these instances need UndecidableInstances, -- because they do not satisfy the coverage condition. -instance (MonadState s m) => MonadState s (ContT r m) where+instance MonadState s m => MonadState s (ContT r m) where get = lift get put = lift . put+ state = lift . state instance (Error e, MonadState s m) => MonadState s (ErrorT e m) where get = lift get put = lift . put+ state = lift . state -instance (MonadState s m) => MonadState s (IdentityT m) where+instance MonadState s m => MonadState s (IdentityT m) where get = lift get put = lift . put+ state = lift . state -instance (MonadState s m) => MonadState s (ListT m) where+instance MonadState s m => MonadState s (ListT m) where get = lift get put = lift . put+ state = lift . state -instance (MonadState s m) => MonadState s (MaybeT m) where+instance MonadState s m => MonadState s (MaybeT m) where get = lift get put = lift . put+ state = lift . state -instance (MonadState s m) => MonadState s (ReaderT r m) where+instance MonadState s m => MonadState s (ReaderT r m) where get = lift get put = lift . put+ state = lift . state instance (Monoid w, MonadState s m) => MonadState s (Lazy.WriterT w m) where get = lift get put = lift . put+ state = lift . state instance (Monoid w, MonadState s m) => MonadState s (Strict.WriterT w m) where get = lift get put = lift . put+ state = lift . state
Control/Monad/State/Lazy.hs view
@@ -25,7 +25,6 @@ gets, -- * The State monad State,- state, runState, evalState, execState,@@ -48,7 +47,7 @@ import Control.Monad.Trans import Control.Monad.Trans.State.Lazy- (State, state, runState, evalState, execState, mapState, withState,+ (State, runState, evalState, execState, mapState, withState, StateT(..), evalStateT, execStateT, mapStateT, withStateT) import Control.Monad
Control/Monad/State/Strict.hs view
@@ -25,7 +25,6 @@ gets, -- * The State monad State,- state, runState, evalState, execState,@@ -48,7 +47,7 @@ import Control.Monad.Trans import Control.Monad.Trans.State.Strict- (State, state, runState, evalState, execState, mapState, withState,+ (State, runState, evalState, execState, mapState, withState, StateT(..), evalStateT, execStateT, mapStateT, withStateT) import Control.Monad
Control/Monad/Writer/Class.hs view
@@ -31,15 +31,15 @@ import Control.Monad.Trans.Maybe as Maybe import Control.Monad.Trans.Reader import qualified Control.Monad.Trans.RWS.Lazy as LazyRWS (- RWST, tell, listen, pass)+ RWST, writer, tell, listen, pass) import qualified Control.Monad.Trans.RWS.Strict as StrictRWS (- RWST, tell, listen, pass)+ RWST, writer, tell, listen, pass) import Control.Monad.Trans.State.Lazy as Lazy import Control.Monad.Trans.State.Strict as Strict import qualified Control.Monad.Trans.Writer.Lazy as Lazy (- WriterT, tell, listen, pass)+ WriterT, writer, tell, listen, pass) import qualified Control.Monad.Trans.Writer.Strict as Strict (- WriterT, tell, listen, pass)+ WriterT, writer, tell, listen, pass) import Control.Monad.Trans.Class (lift) import Control.Monad@@ -58,8 +58,16 @@ -- the written object. class (Monoid w, Monad m) => MonadWriter w m | m -> w where+ -- | @'writer' (a,w)@ embeds a simple writer action.+ writer :: (a,w) -> m a+ writer ~(a, w) = do+ tell w+ return a+ -- | @'tell' w@ is an action that produces the output @w@. tell :: w -> m ()+ tell w = writer ((),w)+ -- | @'listen' m@ is an action that executes the action @m@ and adds -- its output to the value of the computation. listen :: m a -> m (a, w)@@ -72,7 +80,7 @@ -- the result of applying @f@ to the output to the value of the computation. -- -- * @'listens' f m = 'liftM' (id *** f) ('listen' m)@-listens :: (MonadWriter w m) => (w -> b) -> m a -> m (a, b)+listens :: MonadWriter w m => (w -> b) -> m a -> m (a, b) listens f m = do ~(a, w) <- listen m return (a, f w)@@ -82,27 +90,31 @@ -- unchanged. -- -- * @'censor' f m = 'pass' ('liftM' (\\x -> (x,f)) m)@-censor :: (MonadWriter w m) => (w -> w) -> m a -> m a+censor :: MonadWriter w m => (w -> w) -> m a -> m a censor f m = pass $ do a <- m return (a, f) instance (Monoid w, Monad m) => MonadWriter w (Lazy.WriterT w m) where+ writer = Lazy.writer tell = Lazy.tell listen = Lazy.listen pass = Lazy.pass instance (Monoid w, Monad m) => MonadWriter w (Strict.WriterT w m) where+ writer = Strict.writer tell = Strict.tell listen = Strict.listen pass = Strict.pass instance (Monoid w, Monad m) => MonadWriter w (LazyRWS.RWST r w s m) where+ writer = LazyRWS.writer tell = LazyRWS.tell listen = LazyRWS.listen pass = LazyRWS.pass instance (Monoid w, Monad m) => MonadWriter w (StrictRWS.RWST r w s m) where+ writer = StrictRWS.writer tell = StrictRWS.tell listen = StrictRWS.listen pass = StrictRWS.pass@@ -114,31 +126,37 @@ -- because they do not satisfy the coverage condition. instance (Error e, MonadWriter w m) => MonadWriter w (ErrorT e m) where+ writer = lift . writer tell = lift . tell listen = Error.liftListen listen pass = Error.liftPass pass -instance (MonadWriter w m) => MonadWriter w (IdentityT m) where+instance MonadWriter w m => MonadWriter w (IdentityT m) where+ writer = lift . writer tell = lift . tell listen = Identity.mapIdentityT listen pass = Identity.mapIdentityT pass -instance (MonadWriter w m) => MonadWriter w (MaybeT m) where+instance MonadWriter w m => MonadWriter w (MaybeT m) where+ writer = lift . writer tell = lift . tell listen = Maybe.liftListen listen pass = Maybe.liftPass pass -instance (MonadWriter w m) => MonadWriter w (ReaderT r m) where+instance MonadWriter w m => MonadWriter w (ReaderT r m) where+ writer = lift . writer tell = lift . tell listen = mapReaderT listen pass = mapReaderT pass -instance (MonadWriter w m) => MonadWriter w (Lazy.StateT s m) where+instance MonadWriter w m => MonadWriter w (Lazy.StateT s m) where+ writer = lift . writer tell = lift . tell listen = Lazy.liftListen listen pass = Lazy.liftPass pass -instance (MonadWriter w m) => MonadWriter w (Strict.StateT s m) where+instance MonadWriter w m => MonadWriter w (Strict.StateT s m) where+ writer = lift . writer tell = lift . tell listen = Strict.liftListen listen pass = Strict.liftPass pass
Control/Monad/Writer/Lazy.hs view
@@ -24,7 +24,6 @@ censor, -- * The Writer monad Writer,- writer, runWriter, execWriter, mapWriter,@@ -42,7 +41,7 @@ import Control.Monad.Trans import Control.Monad.Trans.Writer.Lazy (- Writer, writer, runWriter, execWriter, mapWriter,+ Writer, runWriter, execWriter, mapWriter, WriterT(..), execWriterT, mapWriterT) import Control.Monad
Control/Monad/Writer/Strict.hs view
@@ -24,7 +24,6 @@ censor, -- * The Writer monad Writer,- writer, runWriter, execWriter, mapWriter,@@ -42,7 +41,7 @@ import Control.Monad.Trans import Control.Monad.Trans.Writer.Strict (- Writer, writer, runWriter, execWriter, mapWriter,+ Writer, runWriter, execWriter, mapWriter, WriterT(..), execWriterT, mapWriterT) import Control.Monad
mtl.cabal view
@@ -1,10 +1,10 @@ name: mtl-version: 2.0.1.1+version: 2.1 cabal-version: >= 1.6 license: BSD3 license-file: LICENSE author: Andy Gill-maintainer: libraries@haskell.org+maintainer: Edward Kmett <ekmett@gmail.com> category: Control synopsis: Monad classes, using functional dependencies description:@@ -15,6 +15,10 @@ (<http://web.cecs.pdx.edu/~mpj/pubs/springschool.html>). build-type: Simple +source-repository head+ type: git+ location: git://github.com/ekmett/mtl.git+ Library exposed-modules: Control.Monad.Cont@@ -38,7 +42,7 @@ Control.Monad.Writer.Class Control.Monad.Writer.Lazy Control.Monad.Writer.Strict- build-depends: base < 6, transformers == 0.2.*+ build-depends: base < 6, transformers == 0.3.* extensions: MultiParamTypeClasses FunctionalDependencies