monads-fd 0.1.0.4 → 0.2.0.0
raw patch · 7 files changed
+15/−560 lines, 7 filesdep +mtldep ~base
Dependencies added: mtl
Dependency ranges changed: base
Files
- Control/Monad/Cont/Class.hs +1/−76
- Control/Monad/Error/Class.hs +1/−113
- Control/Monad/RWS/Class.hs +4/−30
- Control/Monad/Reader/Class.hs +1/−104
- Control/Monad/State/Class.hs +1/−106
- Control/Monad/Writer/Class.hs +1/−119
- monads-fd.cabal +6/−12
Control/Monad/Cont/Class.hs view
@@ -52,79 +52,4 @@ MonadCont(..), ) where -import Control.Monad.Trans.Cont (ContT)-import qualified Control.Monad.Trans.Cont as ContT-import Control.Monad.Trans.Error as Error-import Control.Monad.Trans.Identity as Identity-import Control.Monad.Trans.List as List-import Control.Monad.Trans.Maybe as Maybe-import Control.Monad.Trans.Reader as Reader-import Control.Monad.Trans.RWS.Lazy as LazyRWS-import Control.Monad.Trans.RWS.Strict as StrictRWS-import Control.Monad.Trans.State.Lazy as LazyState-import Control.Monad.Trans.State.Strict as StrictState-import Control.Monad.Trans.Writer.Lazy as LazyWriter-import Control.Monad.Trans.Writer.Strict as StrictWriter--import Control.Monad-import Data.Monoid--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.- Escape continuations allow to abort the current computation and return- a value immediately.- They achieve a similar effect to 'Control.Monad.Error.throwError'- and 'Control.Monad.Error.catchError'- within an 'Control.Monad.Error.Error' monad.- Advantage of this function over calling @return@ is that it makes- the continuation explicit,- allowing more flexibility and better control- (see examples in "Control.Monad.Cont").-- The standard idiom used with @callCC@ is to provide a lambda-expression- to name the continuation. Then calling the named continuation anywhere- within its scope will escape from the computation,- even if it is many layers deep within nested computations.- -}- callCC :: ((a -> m b) -> m a) -> m a--instance MonadCont (ContT r m) where- callCC = ContT.callCC---- ------------------------------------------------------------------------------ Instances for other mtl transformers--instance (Error e, MonadCont m) => MonadCont (ErrorT e m) where- callCC = Error.liftCallCC callCC--instance (MonadCont m) => MonadCont (IdentityT m) where- callCC = Identity.liftCallCC callCC--instance (MonadCont m) => MonadCont (ListT m) where- callCC = List.liftCallCC callCC--instance (MonadCont m) => MonadCont (MaybeT m) where- callCC = Maybe.liftCallCC callCC--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- callCC = LazyRWS.liftCallCC' callCC--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- callCC = LazyState.liftCallCC' callCC--instance (MonadCont m) => MonadCont (StrictState.StateT s m) where- callCC = StrictState.liftCallCC' callCC--instance (Monoid w, MonadCont m) => MonadCont (LazyWriter.WriterT w m) where- callCC = LazyWriter.liftCallCC callCC--instance (Monoid w, MonadCont m) => MonadCont (StrictWriter.WriterT w m) where- callCC = StrictWriter.liftCallCC callCC+import "mtl" Control.Monad.Cont.Class
Control/Monad/Error/Class.hs view
@@ -1,5 +1,3 @@-{-# LANGUAGE UndecidableInstances #-}- {- | Module : Control.Monad.Error.Class Copyright : (c) Michael Weber <michael.weber@post.rwth-aachen.de> 2001,@@ -38,114 +36,4 @@ MonadError(..), ) where -import Control.Monad.Trans.Error (Error(..), ErrorT)-import qualified Control.Monad.Trans.Error as ErrorT (throwError, catchError)-import Control.Monad.Trans.Identity as Identity-import Control.Monad.Trans.List as List-import Control.Monad.Trans.Maybe as Maybe-import Control.Monad.Trans.Reader as Reader-import Control.Monad.Trans.RWS.Lazy as LazyRWS-import Control.Monad.Trans.RWS.Strict as StrictRWS-import Control.Monad.Trans.State.Lazy as LazyState-import Control.Monad.Trans.State.Strict as StrictState-import Control.Monad.Trans.Writer.Lazy as LazyWriter-import Control.Monad.Trans.Writer.Strict as StrictWriter--import Control.Monad.Trans.Class (lift)-import Control.Exception (IOException)-import Control.Monad-import Control.Monad.Instances ()-import Data.Monoid--{- |-The strategy of combining computations that can throw exceptions-by bypassing bound functions-from the point an exception is thrown to the point that it is handled.--Is parameterized over the type of error information and-the monad type constructor.-It is common to use @'Data.Either' String@ as the monad type constructor-for an error monad in which error descriptions take the form of strings.-In that case and many other common cases the resulting monad is already defined-as an instance of the 'MonadError' class.-You can also define your own error type and\/or use a monad type constructor-other than @'Either' 'String'@ or @'Either' 'IOError'@.-In these cases you will have to explicitly define instances of the 'Error'-and\/or 'MonadError' classes.--}-class (Monad m) => MonadError e m | m -> e where- -- | Is used within a monadic computation to begin exception processing.- throwError :: e -> m a-- {- |- A handler function to handle previous errors and return to normal execution.- A common idiom is:-- > do { action1; action2; action3 } `catchError` handler-- where the @action@ functions can call 'throwError'.- Note that @handler@ and the do-block must have the same return type.- -}- catchError :: m a -> (e -> m a) -> m a--instance MonadError IOException IO where- throwError = ioError- catchError = catch---- ------------------------------------------------------------------------------ Our parameterizable error monad--instance (Error e) => MonadError e (Either e) where- throwError = Left- Left l `catchError` h = h l- Right r `catchError` _ = Right r--instance (Monad m, Error e) => MonadError e (ErrorT e m) where- throwError = ErrorT.throwError- catchError = ErrorT.catchError---- ------------------------------------------------------------------------------ Instances for other mtl transformers------ All of these instances need UndecidableInstances,--- because they do not satisfy the coverage condition.--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- throwError = lift . throwError- catchError = List.liftCatch catchError--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- throwError = lift . throwError- catchError = Reader.liftCatch catchError--instance (Monoid w, MonadError e m) => MonadError e (LazyRWS.RWST r w s m) where- throwError = lift . throwError- catchError = LazyRWS.liftCatch catchError--instance (Monoid w, MonadError e m) => MonadError e (StrictRWS.RWST r w s m) where- throwError = lift . throwError- catchError = StrictRWS.liftCatch catchError--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- throwError = lift . throwError- catchError = StrictState.liftCatch catchError--instance (Monoid w, MonadError e m) => MonadError e (LazyWriter.WriterT w m) where- throwError = lift . throwError- catchError = LazyWriter.liftCatch catchError--instance (Monoid w, MonadError e m) => MonadError e (StrictWriter.WriterT w m) where- throwError = lift . throwError- catchError = StrictWriter.liftCatch catchError+import "mtl" Control.Monad.Error.Class
Control/Monad/RWS/Class.hs view
@@ -1,6 +1,3 @@-{-# LANGUAGE UndecidableInstances #-}--- Search for UndecidableInstances to see why this is needed- ----------------------------------------------------------------------------- -- | -- Module : Control.Monad.RWS.Class@@ -28,30 +25,7 @@ module Control.Monad.Writer.Class, ) where -import Control.Monad.Reader.Class-import Control.Monad.State.Class-import Control.Monad.Writer.Class--import Control.Monad.Trans.Error(Error, ErrorT)-import Control.Monad.Trans.Maybe(MaybeT)-import Control.Monad.Trans.Identity(IdentityT)-import Control.Monad.Trans.RWS.Lazy as Lazy (RWST)-import qualified Control.Monad.Trans.RWS.Strict as Strict (RWST)--import Data.Monoid--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)+import "mtl" Control.Monad.RWS.Class+import "mtl" Control.Monad.Reader.Class+import "mtl" Control.Monad.State.Class+import "mtl" Control.Monad.Writer.Class
Control/Monad/Reader/Class.hs view
@@ -1,5 +1,3 @@-{-# LANGUAGE UndecidableInstances #-}--- Search for UndecidableInstances to see why this is needed {- | Module : Control.Monad.Reader.Class Copyright : (c) Andy Gill 2001,@@ -43,105 +41,4 @@ asks, ) where -import Control.Monad.Trans.Cont as Cont-import Control.Monad.Trans.Error-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 Control.Monad.Trans.State.Lazy as Lazy-import Control.Monad.Trans.State.Strict as Strict-import Control.Monad.Trans.Writer.Lazy as Lazy-import Control.Monad.Trans.Writer.Strict as Strict--import Control.Monad.Trans.Class (lift)-import Control.Monad-import Data.Monoid---- ------------------------------------------------------------------------------- class MonadReader--- asks for the internal (non-mutable) state.---- | 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- -- | 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.- -> m a---- | Retrieves a function of the current 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)---- ------------------------------------------------------------------------------- The partially applied function type is a simple reader monad--instance MonadReader r ((->) r) where- ask = id- local f m = m . f--instance (Monad m) => MonadReader r (ReaderT r m) where- ask = ReaderT.ask- local = ReaderT.local--instance (Monad m, Monoid w) => MonadReader r (LazyRWS.RWST r w s m) where- ask = LazyRWS.ask- local = LazyRWS.local--instance (Monad m, Monoid w) => MonadReader r (StrictRWS.RWST r w s m) where- ask = StrictRWS.ask- local = StrictRWS.local---- ------------------------------------------------------------------------------ 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- ask = lift ask- local = Cont.liftLocal ask local--instance (Error e, MonadReader r m) => MonadReader r (ErrorT e m) where- ask = lift ask- local = mapErrorT . local--instance (MonadReader r m) => MonadReader r (IdentityT m) where- ask = lift ask- local = mapIdentityT . local--instance (MonadReader r m) => MonadReader r (ListT m) where- ask = lift ask- local = mapListT . local--instance (MonadReader r m) => MonadReader r (MaybeT m) where- ask = lift ask- local = mapMaybeT . local--instance (MonadReader r m) => MonadReader r (Lazy.StateT s m) where- ask = lift ask- local = Lazy.mapStateT . local--instance (MonadReader r m) => MonadReader r (Strict.StateT s m) where- ask = lift ask- local = Strict.mapStateT . local--instance (Monoid w, MonadReader r m) => MonadReader r (Lazy.WriterT w m) where- ask = lift ask- local = Lazy.mapWriterT . local--instance (Monoid w, MonadReader r m) => MonadReader r (Strict.WriterT w m) where- ask = lift ask- local = Strict.mapWriterT . local+import "mtl" Control.Monad.Reader.Class
Control/Monad/State/Class.hs view
@@ -1,6 +1,3 @@-{-# LANGUAGE UndecidableInstances #-}--- Search for UndecidableInstances to see why this is needed- ----------------------------------------------------------------------------- -- | -- Module : Control.Monad.State.Class@@ -28,106 +25,4 @@ gets, ) where -import Control.Monad.Trans.Cont-import Control.Monad.Trans.Error-import Control.Monad.Trans.Identity-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 Control.Monad.Trans.Writer.Lazy as Lazy-import Control.Monad.Trans.Writer.Strict as Strict--import Control.Monad.Trans.Class (lift)-import Control.Monad-import Data.Monoid---- -----------------------------------------------------------------------------class (Monad m) => MonadState s m | m -> s where- -- | Return the state from the internals of the monad.- get :: m s- -- | Replace the state inside the monad.- put :: s -> m ()---- | Monadic state transformer.------ Maps an old state to a new state inside a state monad.--- The old state is thrown away.------ > Main> :t modify ((+1) :: Int -> Int)--- > modify (...) :: (MonadState Int a) => a ()------ 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)---- | Gets specific component of the state, using a projection function--- supplied.--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- get = Lazy.get- put = Lazy.put--instance (Monad m) => MonadState s (Strict.StateT s m) where- get = Strict.get- put = Strict.put--instance (Monad m, Monoid w) => MonadState s (LazyRWS.RWST r w s m) where- get = LazyRWS.get- put = LazyRWS.put--instance (Monad m, Monoid w) => MonadState s (StrictRWS.RWST r w s m) where- get = StrictRWS.get- put = StrictRWS.put---- ------------------------------------------------------------------------------ Instances for other mtl transformers------ All of these instances need UndecidableInstances,--- because they do not satisfy the coverage condition.--instance (MonadState s m) => MonadState s (ContT r m) where- get = lift get- put = lift . put--instance (Error e, MonadState s m) => MonadState s (ErrorT e m) where- get = lift get- put = lift . put--instance (MonadState s m) => MonadState s (IdentityT m) where- get = lift get- put = lift . put--instance (MonadState s m) => MonadState s (ListT m) where- get = lift get- put = lift . put--instance (MonadState s m) => MonadState s (MaybeT m) where- get = lift get- put = lift . put--instance (MonadState s m) => MonadState s (ReaderT r m) where- get = lift get- put = lift . put--instance (Monoid w, MonadState s m) => MonadState s (Lazy.WriterT w m) where- get = lift get- put = lift . put--instance (Monoid w, MonadState s m) => MonadState s (Strict.WriterT w m) where- get = lift get- put = lift . put+import "mtl" Control.Monad.State.Class
Control/Monad/Writer/Class.hs view
@@ -1,6 +1,3 @@-{-# LANGUAGE UndecidableInstances #-}--- Search for UndecidableInstances to see why this is needed- ----------------------------------------------------------------------------- -- | -- Module : Control.Monad.Writer.Class@@ -27,119 +24,4 @@ censor, ) where -import Control.Monad.Trans.Error as Error-import Control.Monad.Trans.Identity as Identity-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)-import qualified Control.Monad.Trans.RWS.Strict as StrictRWS (- RWST, 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)-import qualified Control.Monad.Trans.Writer.Strict as Strict (- WriterT, tell, listen, pass)--import Control.Monad.Trans.Class (lift)-import Control.Monad-import Data.Monoid---- ------------------------------------------------------------------------------ MonadWriter class------ tell is like tell on the MUD's it shouts to monad--- what you want to be heard. The monad carries this 'packet'--- upwards, merging it if needed (hence the Monoid requirement).------ listen listens to a monad acting, and returns what the monad "said".------ pass lets you provide a writer transformer which changes internals of--- the written object.--class (Monoid w, Monad m) => MonadWriter w m | m -> w where- -- | @'tell' w@ is an action that produces the output @w@.- tell :: w -> m ()- -- | @'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)- -- | @'pass' m@ is an action that executes the action @m@, which- -- returns a value and a function, and returns the value, applying- -- the function to the output.- pass :: m (a, w -> w) -> m a---- | @'listens' f m@ is an action that executes the action @m@ and adds--- 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 f m = do- ~(a, w) <- listen m- return (a, f w)---- | @'censor' f m@ is an action that executes the action @m@ and--- applies the function @f@ to its output, leaving the return value--- unchanged.------ * @'censor' f m = 'pass' ('liftM' (\\x -> (x,f)) m)@-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- tell = Lazy.tell- listen = Lazy.listen- pass = Lazy.pass--instance (Monoid w, Monad m) => MonadWriter w (Strict.WriterT w m) where- tell = Strict.tell- listen = Strict.listen- pass = Strict.pass--instance (Monoid w, Monad m) => MonadWriter w (LazyRWS.RWST r w s m) where- tell = LazyRWS.tell- listen = LazyRWS.listen- pass = LazyRWS.pass--instance (Monoid w, Monad m) => MonadWriter w (StrictRWS.RWST r w s m) where- tell = StrictRWS.tell- listen = StrictRWS.listen- pass = StrictRWS.pass---- ------------------------------------------------------------------------------ Instances for other mtl transformers------ All of these instances need UndecidableInstances,--- because they do not satisfy the coverage condition.--instance (Error e, MonadWriter w m) => MonadWriter w (ErrorT e m) where- tell = lift . tell- listen = Error.liftListen listen- pass = Error.liftPass pass--instance (MonadWriter w m) => MonadWriter w (IdentityT m) where- tell = lift . tell- listen = Identity.mapIdentityT listen- pass = Identity.mapIdentityT pass--instance (MonadWriter w m) => MonadWriter w (MaybeT m) where- tell = lift . tell- listen = Maybe.liftListen listen- pass = Maybe.liftPass pass--instance (MonadWriter w m) => MonadWriter w (ReaderT r m) where- tell = lift . tell- listen = mapReaderT listen- pass = mapReaderT pass--instance (MonadWriter w m) => MonadWriter w (Lazy.StateT s m) where- tell = lift . tell- listen = Lazy.liftListen listen- pass = Lazy.liftPass pass--instance (MonadWriter w m) => MonadWriter w (Strict.StateT s m) where- tell = lift . tell- listen = Strict.liftListen listen- pass = Strict.liftPass pass+import "mtl" Control.Monad.Writer.Class
monads-fd.cabal view
@@ -1,5 +1,5 @@ name: monads-fd-version: 0.1.0.4+version: 0.2.0.0 cabal-version: >= 1.6 license: BSD3 license-file: LICENSE@@ -8,13 +8,9 @@ category: Control synopsis: Monad classes, using functional dependencies description:- Monad classes using functional dependencies, with instances- for various monad transformers, inspired by the paper- /Functional Programming with Overloading and Higher-Order Polymorphism/,- by Mark P Jones, in /Advanced School of Functional Programming/, 1995- (<http://web.cecs.pdx.edu/~mpj/pubs/springschool.html>).- .- This package is almost a compatible replacement for the @mtl@ package.+ Now that @mtl@ has been upgraded to depend on @transformers@,+ this package is a backwards compatibility stub re-exporting the+ @mtl@ package. build-type: Simple Library@@ -40,8 +36,6 @@ 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.2.*, mtl == 2.* extensions:- MultiParamTypeClasses- FunctionalDependencies- FlexibleInstances+ PackageImports