transformers 0.0.1.0 → 0.1.0.0
raw patch · 15 files changed
+174/−27 lines, 15 files
Files
- Control/Monad/Identity.hs +6/−1
- Control/Monad/Trans.hs +1/−1
- Control/Monad/Trans/Cont.hs +5/−0
- Control/Monad/Trans/Error.hs +18/−1
- Control/Monad/Trans/List.hs +11/−2
- Control/Monad/Trans/RWS.hs +1/−1
- Control/Monad/Trans/RWS/Lazy.hs +24/−3
- Control/Monad/Trans/RWS/Strict.hs +23/−2
- Control/Monad/Trans/Reader.hs +12/−3
- Control/Monad/Trans/State.hs +1/−1
- Control/Monad/Trans/State/Lazy.hs +23/−3
- Control/Monad/Trans/State/Strict.hs +23/−3
- Control/Monad/Trans/Writer/Lazy.hs +12/−2
- Control/Monad/Trans/Writer/Strict.hs +12/−2
- transformers.cabal +2/−2
Control/Monad/Identity.hs view
@@ -34,7 +34,7 @@ Inspired by the paper /Functional Programming with Overloading and Higher-Order Polymorphism/,- Mark P Jones (<http://www.cse.ogi.edu/~mpj/>)+ Mark P Jones (<http://web.cecs.pdx.edu/~mpj/>) Advanced School of Functional Programming, 1995. -} @@ -42,6 +42,7 @@ Identity(..), ) where +import Control.Applicative import Control.Monad import Control.Monad.Fix @@ -83,6 +84,10 @@ instance Functor Identity where fmap f m = Identity (f (runIdentity m))++instance Applicative Identity where+ pure a = Identity a+ Identity f <*> Identity x = Identity (f x) instance Monad Identity where return a = Identity a
Control/Monad/Trans.hs view
@@ -14,7 +14,7 @@ -- Inspired by the paper -- /Functional Programming with Overloading and -- Higher-Order Polymorphism/,--- Mark P Jones (<http://www.cse.ogi.edu/~mpj/>)+-- Mark P Jones (<http://web.cecs.pdx.edu/~mpj/>) -- Advanced School of Functional Programming, 1995. -----------------------------------------------------------------------------
Control/Monad/Trans/Cont.hs view
@@ -31,6 +31,7 @@ import Control.Monad.Identity import Control.Monad.Trans +import Control.Applicative import Control.Monad {- |@@ -75,6 +76,10 @@ instance Functor (ContT r m) where fmap f m = ContT $ \c -> runContT m (c . f)++instance Applicative (ContT r m) where+ pure a = ContT ($ a)+ f <*> v = ContT $ \ k -> runContT f $ \ g -> runContT v (k . g) instance (Monad m) => Monad (ContT r m) where return a = ContT ($ a)
Control/Monad/Trans/Error.hs view
@@ -29,7 +29,7 @@ {- Rendered by Michael Weber <mailto:michael.weber@post.rwth-aachen.de>, inspired by the Haskell Monad Template Library from- Andy Gill (<http://www.cse.ogi.edu/~andy/>)+ Andy Gill (<http://web.cecs.pdx.edu/~andy/>) -} module Control.Monad.Trans.Error ( -- * The ErrorT monad transformer@@ -45,6 +45,7 @@ liftPass, ) where +import Control.Applicative import Control.Exception (IOException) import Control.Monad import Control.Monad.Fix@@ -136,6 +137,22 @@ instance (Monad m) => Functor (ErrorT e m) where fmap f = ErrorT . liftM (fmap f) . runErrorT++instance (Monad m) => Applicative (ErrorT e m) where+ pure a = ErrorT $ return (Right a)+ f <*> v = ErrorT $ do+ mf <- runErrorT f+ case mf of+ Left e -> return (Left e)+ Right k -> do+ mv <- runErrorT v+ case mv of+ Left e -> return (Left e)+ Right x -> return (Right (k x))++instance (Monad m, Error e) => Alternative (ErrorT e m) where+ empty = mzero+ (<|>) = mplus instance (Monad m, Error e) => Monad (ErrorT e m) where return a = ErrorT $ return (Right a)
Control/Monad/Trans/List.hs view
@@ -22,6 +22,7 @@ liftCatch, ) where +import Control.Applicative import Control.Monad import Control.Monad.Trans @@ -33,8 +34,16 @@ mapListT :: (m [a] -> n [b]) -> ListT m a -> ListT n b mapListT f m = ListT $ f (runListT m) -instance (Monad m) => Functor (ListT m) where- fmap f = mapListT $ liftM $ map f+instance (Functor m) => Functor (ListT m) where+ fmap f = mapListT $ fmap $ map f++instance (Applicative m) => Applicative (ListT m) where+ pure a = ListT $ pure [a]+ f <*> v = ListT $ (<*>) <$> runListT f <*> runListT v++instance (Applicative m) => Alternative (ListT m) where+ empty = ListT $ pure []+ m <|> n = ListT $ (++) <$> runListT m <*> runListT n instance (Monad m) => Monad (ListT m) where return a = ListT $ return [a]
Control/Monad/Trans/RWS.hs view
@@ -14,7 +14,7 @@ -- Inspired by the paper -- /Functional Programming with Overloading and -- Higher-Order Polymorphism/,--- Mark P Jones (<http://www.cse.ogi.edu/~mpj/>)+-- Mark P Jones (<http://web.cecs.pdx.edu/~mpj/>) -- Advanced School of Functional Programming, 1995. -----------------------------------------------------------------------------
Control/Monad/Trans/RWS/Lazy.hs view
@@ -14,7 +14,7 @@ -- Inspired by the paper -- /Functional Programming with Overloading and -- Higher-Order Polymorphism/,--- Mark P Jones (<http://www.cse.ogi.edu/~mpj/>)+-- Mark P Jones (<http://web.cecs.pdx.edu/~mpj/>) -- Advanced School of Functional Programming, 1995. ----------------------------------------------------------------------------- @@ -50,9 +50,11 @@ gets, -- * Lifting other operations liftCallCC,+ liftCallCC', liftCatch, ) where +import Control.Applicative import Control.Monad import Control.Monad.Fix import Control.Monad.Identity@@ -106,9 +108,17 @@ instance (Monad m) => Functor (RWST r w s m) where fmap f m = RWST $ \r s -> do- ~(a, s', w) <- runRWST m r s+ (a, s', w) <- runRWST m r s return (f a, s', w) +instance (Monoid w, Monad m) => Applicative (RWST r w s m) where+ pure = return+ (<*>) = ap++instance (Monoid w, MonadPlus m) => Alternative (RWST r w s m) where+ empty = mzero+ (<|>) = mplus+ instance (Monoid w, Monad m) => Monad (RWST r w s m) where return a = RWST $ \_ s -> return (a, s, mempty) m >>= k = RWST $ \r s -> do@@ -199,11 +209,22 @@ s <- get return (f s) --- | Lift a @callCC@ operation to the new monad.+-- | Uniform lifting of a @callCC@ operation to the new monad.+-- This version rolls back to the original state on entering the+-- continuation. liftCallCC :: (Monoid w) => ((((a,s,w) -> m (b,s,w)) -> m (a,s,w)) -> m (a,s,w)) -> ((a -> RWST r w s m b) -> RWST r w s m a) -> RWST r w s m a liftCallCC callCC f = RWST $ \r s ->+ callCC $ \c ->+ runRWST (f (\a -> RWST $ \_ _ -> c (a, s, mempty))) r s++-- | In-situ lifting of a @callCC@ operation to the new monad.+-- This version uses the current state on entering the continuation.+liftCallCC' :: (Monoid w) =>+ ((((a,s,w) -> m (b,s,w)) -> m (a,s,w)) -> m (a,s,w)) ->+ ((a -> RWST r w s m b) -> RWST r w s m a) -> RWST r w s m a+liftCallCC' callCC f = RWST $ \r s -> callCC $ \c -> runRWST (f (\a -> RWST $ \_ s' -> c (a, s', mempty))) r s
Control/Monad/Trans/RWS/Strict.hs view
@@ -14,7 +14,7 @@ -- Inspired by the paper -- /Functional Programming with Overloading and -- Higher-Order Polymorphism/,--- Mark P Jones (<http://www.cse.ogi.edu/~mpj/>)+-- Mark P Jones (<http://web.cecs.pdx.edu/~mpj/>) -- Advanced School of Functional Programming, 1995. ----------------------------------------------------------------------------- @@ -50,9 +50,11 @@ gets, -- * Lifting other operations liftCallCC,+ liftCallCC', liftCatch, ) where +import Control.Applicative import Control.Monad import Control.Monad.Fix import Control.Monad.Identity@@ -109,6 +111,14 @@ (a, s', w) <- runRWST m r s return (f a, s', w) +instance (Monoid w, Monad m) => Applicative (RWST r w s m) where+ pure = return+ (<*>) = ap++instance (Monoid w, MonadPlus m) => Alternative (RWST r w s m) where+ empty = mzero+ (<|>) = mplus+ instance (Monoid w, Monad m) => Monad (RWST r w s m) where return a = RWST $ \_ s -> return (a, s, mempty) m >>= k = RWST $ \r s -> do@@ -199,11 +209,22 @@ s <- get return (f s) --- | Lift a @callCC@ operation to the new monad.+-- | Uniform lifting of a @callCC@ operation to the new monad.+-- This version rolls back to the original state on entering the+-- continuation. liftCallCC :: (Monoid w) => ((((a,s,w) -> m (b,s,w)) -> m (a,s,w)) -> m (a,s,w)) -> ((a -> RWST r w s m b) -> RWST r w s m a) -> RWST r w s m a liftCallCC callCC f = RWST $ \r s ->+ callCC $ \c ->+ runRWST (f (\a -> RWST $ \_ _ -> c (a, s, mempty))) r s++-- | In-situ lifting of a @callCC@ operation to the new monad.+-- This version uses the current state on entering the continuation.+liftCallCC' :: (Monoid w) =>+ ((((a,s,w) -> m (b,s,w)) -> m (a,s,w)) -> m (a,s,w)) ->+ ((a -> RWST r w s m b) -> RWST r w s m a) -> RWST r w s m a+liftCallCC' callCC f = RWST $ \r s -> callCC $ \c -> runRWST (f (\a -> RWST $ \_ s' -> c (a, s', mempty))) r s
Control/Monad/Trans/Reader.hs view
@@ -14,7 +14,7 @@ -- Inspired by the paper -- /Functional Programming with Overloading and -- Higher-Order Polymorphism/,--- Mark P Jones (<http://www.cse.ogi.edu/~mpj/>)+-- Mark P Jones (<http://web.cecs.pdx.edu/~mpj/>) -- Advanced School of Functional Programming, 1995. ----------------------------------------------------------------------------- @@ -41,6 +41,7 @@ import Control.Monad.Identity import Control.Monad.Trans +import Control.Applicative import Control.Monad import Control.Monad.Fix import Control.Monad.Instances ()@@ -81,8 +82,16 @@ withReaderT :: (r' -> r) -> ReaderT r m a -> ReaderT r' m a withReaderT f m = ReaderT $ runReaderT m . f -instance (Monad m) => Functor (ReaderT r m) where- fmap f m = ReaderT (liftM f . runReaderT m)+instance (Functor m) => Functor (ReaderT r m) where+ fmap f m = ReaderT (fmap f . runReaderT m)++instance (Applicative m) => Applicative (ReaderT r m) where+ pure a = ReaderT $ \ _ -> pure a+ f <*> v = ReaderT $ \ r -> runReaderT f r <*> runReaderT v r++instance (Alternative m) => Alternative (ReaderT r m) where+ empty = ReaderT $ \_ -> empty+ m <|> n = ReaderT $ \r -> runReaderT m r <|> runReaderT n r instance (Monad m) => Monad (ReaderT r m) where return a = ReaderT $ \_ -> return a
Control/Monad/Trans/State.hs view
@@ -14,7 +14,7 @@ -- This module is inspired by the paper -- /Functional Programming with Overloading and -- Higher-Order Polymorphism/,--- Mark P Jones (<http://www.cse.ogi.edu/~mpj/>)+-- Mark P Jones (<http://web.cecs.pdx.edu/~mpj/>) -- Advanced School of Functional Programming, 1995. -----------------------------------------------------------------------------
Control/Monad/Trans/State/Lazy.hs view
@@ -14,7 +14,7 @@ -- This module is inspired by the paper -- /Functional Programming with Overloading and -- Higher-Order Polymorphism/,--- Mark P Jones (<http://www.cse.ogi.edu/~mpj/>)+-- Mark P Jones (<http://web.cecs.pdx.edu/~mpj/>) -- Advanced School of Functional Programming, 1995. -- -- See below for examples.@@ -43,11 +43,13 @@ gets, -- * Lifting other operations liftCallCC,+ liftCallCC', liftCatch, liftListen, liftPass, ) where +import Control.Applicative import Control.Monad import Control.Monad.Fix import Control.Monad.Identity@@ -154,8 +156,16 @@ withStateT f m = StateT $ runStateT m . f instance (Monad m) => Functor (StateT s m) where- fmap f = mapStateT $ liftM $ \ ~(x, s') -> (f x, s')+ fmap = liftM +instance (Monad m) => Applicative (StateT s m) where+ pure = return+ (<*>) = ap++instance (MonadPlus m) => Alternative (StateT s m) where+ empty = mzero+ (<|>) = mplus+ instance (Monad m) => Monad (StateT s m) where return a = StateT $ \s -> return (a, s) m >>= k = StateT $ \s -> do@@ -202,10 +212,20 @@ s <- get return (f s) --- | Lift a @callCC@ operation to the new monad.+-- | Uniform lifting of a @callCC@ operation to the new monad.+-- This version rolls back to the original state on entering the+-- continuation. liftCallCC :: ((((a,s) -> m (b,s)) -> m (a,s)) -> m (a,s)) -> ((a -> StateT s m b) -> StateT s m a) -> StateT s m a liftCallCC callCC f = StateT $ \s ->+ callCC $ \c ->+ runStateT (f (\a -> StateT $ \ _ -> c (a, s))) s++-- | In-situ lifting of a @callCC@ operation to the new monad.+-- This version uses the current state on entering the continuation.+liftCallCC' :: ((((a,s) -> m (b,s)) -> m (a,s)) -> m (a,s)) ->+ ((a -> StateT s m b) -> StateT s m a) -> StateT s m a+liftCallCC' callCC f = StateT $ \s -> callCC $ \c -> runStateT (f (\a -> StateT $ \s' -> c (a, s'))) s
Control/Monad/Trans/State/Strict.hs view
@@ -14,7 +14,7 @@ -- This module is inspired by the paper -- /Functional Programming with Overloading and -- Higher-Order Polymorphism/,--- Mark P Jones (<http://www.cse.ogi.edu/~mpj/>)+-- Mark P Jones (<http://web.cecs.pdx.edu/~mpj/>) -- Advanced School of Functional Programming, 1995. -- -- See below for examples.@@ -43,11 +43,13 @@ gets, -- * Lifting other operations liftCallCC,+ liftCallCC', liftCatch, liftListen, liftPass, ) where +import Control.Applicative import Control.Monad import Control.Monad.Fix import Control.Monad.Identity@@ -154,8 +156,16 @@ withStateT f m = StateT $ runStateT m . f instance (Monad m) => Functor (StateT s m) where- fmap f = mapStateT $ liftM $ \ (x, s') -> (f x, s')+ fmap = liftM +instance (Monad m) => Applicative (StateT s m) where+ pure = return+ (<*>) = ap++instance (MonadPlus m) => Alternative (StateT s m) where+ empty = mzero+ (<|>) = mplus+ instance (Monad m) => Monad (StateT s m) where return a = StateT $ \s -> return (a, s) m >>= k = StateT $ \s -> do@@ -202,10 +212,20 @@ s <- get return (f s) --- | Lift a @callCC@ operation to the new monad.+-- | Uniform lifting of a @callCC@ operation to the new monad.+-- This version rolls back to the original state on entering the+-- continuation. liftCallCC :: ((((a,s) -> m (b,s)) -> m (a,s)) -> m (a,s)) -> ((a -> StateT s m b) -> StateT s m a) -> StateT s m a liftCallCC callCC f = StateT $ \s ->+ callCC $ \c ->+ runStateT (f (\a -> StateT $ \ _ -> c (a, s))) s++-- | In-situ lifting of a @callCC@ operation to the new monad.+-- This version uses the current state on entering the continuation.+liftCallCC' :: ((((a,s) -> m (b,s)) -> m (a,s)) -> m (a,s)) ->+ ((a -> StateT s m b) -> StateT s m a) -> StateT s m a+liftCallCC' callCC f = StateT $ \s -> callCC $ \c -> runStateT (f (\a -> StateT $ \s' -> c (a, s'))) s
Control/Monad/Trans/Writer/Lazy.hs view
@@ -40,6 +40,7 @@ liftCatch, ) where +import Control.Applicative import Control.Monad import Control.Monad.Fix import Control.Monad.Identity@@ -76,8 +77,17 @@ mapWriterT :: (m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b mapWriterT f m = WriterT $ f (runWriterT m) -instance (Monad m) => Functor (WriterT w m) where- fmap f = mapWriterT $ liftM $ \ ~(a, w) -> (f a, w)+instance (Functor m) => Functor (WriterT w m) where+ fmap f = mapWriterT $ fmap $ \ ~(a, w) -> (f a, w)++instance (Monoid w, Applicative m) => Applicative (WriterT w m) where+ pure a = WriterT $ pure (a, mempty)+ f <*> v = WriterT $ liftA2 k (runWriterT f) (runWriterT v)+ where k ~(a, w) ~(b, w') = (a b, w `mappend` w')++instance (Monoid w, Alternative m) => Alternative (WriterT w m) where+ empty = WriterT empty+ m <|> n = WriterT $ runWriterT m <|> runWriterT n instance (Monoid w, Monad m) => Monad (WriterT w m) where return a = WriterT $ return (a, mempty)
Control/Monad/Trans/Writer/Strict.hs view
@@ -40,6 +40,7 @@ liftCatch, ) where +import Control.Applicative import Control.Monad import Control.Monad.Fix import Control.Monad.Identity@@ -76,8 +77,17 @@ mapWriterT :: (m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b mapWriterT f m = WriterT $ f (runWriterT m) -instance (Monad m) => Functor (WriterT w m) where- fmap f = mapWriterT $ liftM $ \ (a, w) -> (f a, w)+instance (Functor m) => Functor (WriterT w m) where+ fmap f = mapWriterT $ fmap $ \ (a, w) -> (f a, w)++instance (Monoid w, Applicative m) => Applicative (WriterT w m) where+ pure a = WriterT $ pure (a, mempty)+ f <*> v = WriterT $ liftA2 k (runWriterT f) (runWriterT v)+ where k (a, w) (b, w') = (a b, w `mappend` w')++instance (Monoid w, Alternative m) => Alternative (WriterT w m) where+ empty = WriterT empty+ m <|> n = WriterT $ runWriterT m <|> runWriterT n instance (Monoid w, Monad m) => Monad (WriterT w m) where return a = WriterT $ return (a, mempty)
transformers.cabal view
@@ -1,9 +1,9 @@ name: transformers-version: 0.0.1.0+version: 0.1.0.0 license: BSD3 license-file: LICENSE author: Andy Gill-maintainer: libraries@haskell.org+maintainer: Ross Paterson <ross@soi.city.ac.uk> category: Control synopsis: Concrete monad transformers description: