packages feed

transformers 0.5.1.0 → 0.5.2.0

raw patch · 20 files changed

+446/−8 lines, 20 files

Files

Control/Applicative/Backwards.hs view
@@ -39,9 +39,11 @@  instance (Eq1 f) => Eq1 (Backwards f) where     liftEq eq (Backwards x) (Backwards y) = liftEq eq x y+    {-# INLINE liftEq #-}  instance (Ord1 f) => Ord1 (Backwards f) where     liftCompare comp (Backwards x) (Backwards y) = liftCompare comp x y+    {-# INLINE liftCompare #-}  instance (Read1 f) => Read1 (Backwards f) where     liftReadsPrec rp rl = readsData $@@ -59,26 +61,38 @@ -- | Derived instance. instance (Functor f) => Functor (Backwards f) where     fmap f (Backwards a) = Backwards (fmap f a)+    {-# INLINE fmap #-}  -- | Apply @f@-actions in the reverse order. instance (Applicative f) => Applicative (Backwards f) where     pure a = Backwards (pure a)+    {-# INLINE pure #-}     Backwards f <*> Backwards a = Backwards (a <**> f)+    {-# INLINE (<*>) #-}  -- | Try alternatives in the same order as @f@. instance (Alternative f) => Alternative (Backwards f) where     empty = Backwards empty+    {-# INLINE empty #-}     Backwards x <|> Backwards y = Backwards (x <|> y)+    {-# INLINE (<|>) #-}  -- | Derived instance. instance (Foldable f) => Foldable (Backwards f) where     foldMap f (Backwards t) = foldMap f t+    {-# INLINE foldMap #-}     foldr f z (Backwards t) = foldr f z t+    {-# INLINE foldr #-}     foldl f z (Backwards t) = foldl f z t+    {-# INLINE foldl #-}     foldr1 f (Backwards t) = foldr1 f t+    {-# INLINE foldr1 #-}     foldl1 f (Backwards t) = foldl1 f t+    {-# INLINE foldl1 #-}  -- | Derived instance. instance (Traversable f) => Traversable (Backwards f) where     traverse f (Backwards t) = fmap Backwards (traverse f t)+    {-# INLINE traverse #-}     sequenceA (Backwards t) = fmap Backwards (sequenceA t)+    {-# INLINE sequenceA #-}
Control/Applicative/Lift.hs view
@@ -46,12 +46,14 @@     liftEq _ (Pure _) (Other _) = False     liftEq _ (Other _) (Pure _) = False     liftEq eq (Other y1) (Other y2) = liftEq eq y1 y2+    {-# INLINE liftEq #-}  instance (Ord1 f) => Ord1 (Lift f) where     liftCompare comp (Pure x1) (Pure x2) = comp x1 x2     liftCompare _ (Pure _) (Other _) = LT     liftCompare _ (Other _) (Pure _) = GT     liftCompare comp (Other y1) (Other y2) = liftCompare comp y1 y2+    {-# INLINE liftCompare #-}  instance (Read1 f) => Read1 (Lift f) where     liftReadsPrec rp rl = readsData $@@ -71,39 +73,48 @@ instance (Functor f) => Functor (Lift f) where     fmap f (Pure x) = Pure (f x)     fmap f (Other y) = Other (fmap f y)+    {-# INLINE fmap #-}  instance (Foldable f) => Foldable (Lift f) where     foldMap f (Pure x) = f x     foldMap f (Other y) = foldMap f y+    {-# INLINE foldMap #-}  instance (Traversable f) => Traversable (Lift f) where     traverse f (Pure x) = Pure <$> f x     traverse f (Other y) = Other <$> traverse f y+    {-# INLINE traverse #-}  -- | A combination is 'Pure' only if both parts are. instance (Applicative f) => Applicative (Lift f) where     pure = Pure+    {-# INLINE pure #-}     Pure f <*> Pure x = Pure (f x)     Pure f <*> Other y = Other (f <$> y)     Other f <*> Pure x = Other (($ x) <$> f)     Other f <*> Other y = Other (f <*> y)+    {-# INLINE (<*>) #-}  -- | A combination is 'Pure' only either part is. instance (Alternative f) => Alternative (Lift f) where     empty = Other empty+    {-# INLINE empty #-}     Pure x <|> _ = Pure x     Other _ <|> Pure y = Pure y     Other x <|> Other y = Other (x <|> y)+    {-# INLINE (<|>) #-}  -- | Projection to the other functor. unLift :: (Applicative f) => Lift f a -> f a unLift (Pure x) = pure x unLift (Other e) = e+{-# INLINE unLift #-}  -- | Apply a transformation to the other computation. mapLift :: (f a -> g a) -> Lift f a -> Lift g a mapLift _ (Pure x) = Pure x mapLift f (Other e) = Other (f e)+{-# INLINE mapLift #-}  -- | An applicative functor that collects a monoid (e.g. lists) of errors. -- A sequence of computations fails if any of its components do, but@@ -129,7 +140,9 @@ runErrors :: Errors e a -> Either e a runErrors (Other (Constant e)) = Left e runErrors (Pure x) = Right x+{-# INLINE runErrors #-}  -- | Report an error. failure :: e -> Errors e a failure e = Other (Constant e)+{-# INLINE failure #-}
Control/Monad/Trans/Class.hs view
@@ -78,6 +78,11 @@  > mapStateT t :: StateT s M a -> StateT s N a +For these monad transformers, 'lift' is a natural transformation in the+category of monads, i.e. for any monad transformation @t :: M a -> N a@,++* @map@/XXX/@T t . 'lift' = 'lift' . t@+ Each of the monad transformers introduces relevant operations. In a sequence of monad transformers, most of these operations.can be lifted through other transformers using 'lift' or the @map@/XXX/@T@
Control/Monad/Trans/Cont.hs view
@@ -72,6 +72,7 @@ -- (The inverse of 'runCont') cont :: ((a -> r) -> r) -> Cont r a cont f = ContT (\ c -> Identity (f (runIdentity . c)))+{-# INLINE cont #-}  -- | The result of running a CPS computation with a given final continuation. -- (The inverse of 'cont')@@ -81,6 +82,7 @@                         -- the final result (often 'id').     -> r runCont m k = runIdentity (runContT m (Identity . k))+{-# INLINE runCont #-}  -- | The result of running a CPS computation with the identity as the -- final continuation.@@ -88,6 +90,7 @@ -- * @'evalCont' ('return' x) = x@ evalCont :: Cont r r -> r evalCont m = runIdentity (evalContT m)+{-# INLINE evalCont #-}  -- | Apply a function to transform the result of a continuation-passing -- computation.@@ -95,6 +98,7 @@ -- * @'runCont' ('mapCont' f m) = f . 'runCont' m@ mapCont :: (r -> r) -> Cont r a -> Cont r a mapCont f = mapContT (Identity . f . runIdentity)+{-# INLINE mapCont #-}  -- | Apply a function to transform the continuation passed to a CPS -- computation.@@ -102,6 +106,7 @@ -- * @'runCont' ('withCont' f m) = 'runCont' m . f@ withCont :: ((b -> r) -> (a -> r)) -> Cont r a -> Cont r b withCont f = withContT ((Identity .) . f . (runIdentity .))+{-# INLINE withCont #-}  -- | @'reset' m@ delimits the continuation of any 'shift' inside @m@. --@@ -109,6 +114,7 @@ -- reset :: Cont r r -> Cont r' r reset = resetT+{-# INLINE reset #-}  -- | @'shift' f@ captures the continuation up to the nearest enclosing -- 'reset' and passes it to @f@:@@ -117,9 +123,15 @@ -- shift :: ((a -> r) -> Cont r r) -> Cont r a shift f = shiftT (f . (runIdentity .))+{-# INLINE shift #-}  -- | The continuation monad transformer.--- Can be used to add continuation handling to other monads.+-- Can be used to add continuation handling to any type constructor:+-- the 'Monad' instance and most of the operations do not require @m@+-- to be a monad.+--+-- 'ContT' is not a functor on the category of monads, and many operations+-- cannot be lifted through it. newtype ContT r m a = ContT { runContT :: (a -> m r) -> m r }  -- | The result of running a CPS computation with 'return' as the@@ -128,13 +140,17 @@ -- * @'evalContT' ('lift' m) = m@ evalContT :: (Monad m) => ContT r m r -> m r evalContT m = runContT m return+{-# INLINE evalContT #-}  -- | Apply a function to transform the result of a continuation-passing--- computation.+-- computation.  This has a more restricted type than the @map@ operations+-- for other monad transformers, because 'ContT' does not define a functor+-- in the category of monads. -- -- * @'runContT' ('mapContT' f m) = f . 'runContT' m@ mapContT :: (m r -> m r) -> ContT r m a -> ContT r m a mapContT f m = ContT $ f . runContT m+{-# INLINE mapContT #-}  -- | Apply a function to transform the continuation passed to a CPS -- computation.@@ -142,30 +158,39 @@ -- * @'runContT' ('withContT' f m) = 'runContT' m . f@ withContT :: ((b -> m r) -> (a -> m r)) -> ContT r m a -> ContT r m b withContT f m = ContT $ runContT m . f+{-# INLINE withContT #-}  instance Functor (ContT r m) where     fmap f m = ContT $ \ c -> runContT m (c . f)+    {-# INLINE fmap #-}  instance Applicative (ContT r m) where     pure x  = ContT ($ x)+    {-# INLINE pure #-}     f <*> v = ContT $ \ c -> runContT f $ \ g -> runContT v (c . g)+    {-# INLINE (<*>) #-}  instance Monad (ContT r m) where #if !(MIN_VERSION_base(4,8,0))     return x = ContT ($ x)+    {-# INLINE return #-} #endif     m >>= k  = ContT $ \ c -> runContT m (\ x -> runContT (k x) c)+    {-# INLINE (>>=) #-}  #if MIN_VERSION_base(4,9,0) instance (Fail.MonadFail m) => Fail.MonadFail (ContT r m) where     fail msg = ContT $ \ _ -> Fail.fail msg+    {-# INLINE fail #-} #endif  instance MonadTrans (ContT r) where     lift m = ContT (m >>=)+    {-# INLINE lift #-}  instance (MonadIO m) => MonadIO (ContT r m) where     liftIO = lift . liftIO+    {-# INLINE liftIO #-}  -- | @callCC@ (call-with-current-continuation) calls its argument -- function, passing it the current continuation.  It provides@@ -184,6 +209,7 @@ -- layers deep within nested computations. callCC :: ((a -> ContT r m b) -> ContT r m a) -> ContT r m a callCC f = ContT $ \ c -> runContT (f (\ x -> ContT $ \ _ -> c x)) c+{-# INLINE callCC #-}  -- | @'resetT' m@ delimits the continuation of any 'shiftT' inside @m@. --@@ -191,6 +217,7 @@ -- resetT :: (Monad m) => ContT r m r -> ContT r' m r resetT = lift . evalContT+{-# INLINE resetT #-}  -- | @'shiftT' f@ captures the continuation up to the nearest enclosing -- 'resetT' and passes it to @f@:@@ -199,6 +226,7 @@ -- shiftT :: (Monad m) => ((a -> m r) -> ContT r m r) -> ContT r m a shiftT f = ContT (evalContT . f)+{-# INLINE shiftT #-}  -- | @'liftLocal' ask local@ yields a @local@ function for @'ContT' r m@. liftLocal :: (Monad m) => m r' -> ((r' -> r') -> m r -> m r) ->@@ -206,3 +234,4 @@ liftLocal ask local f m = ContT $ \ c -> do     r <- ask     local f (runContT m (local (const r) . c))+{-# INLINE liftLocal #-}
Control/Monad/Trans/Error.hs view
@@ -90,6 +90,7 @@ catchIOError :: IO a -> (IOError -> IO a) -> IO a catchIOError = catch # endif+#endif  instance (Error e) => Alternative (Either e) where     empty        = Left noMsg@@ -100,7 +101,6 @@     mzero            = Left noMsg     Left _ `mplus` n = n     m      `mplus` _ = m-#endif  #if !(MIN_VERSION_base(4,3,0)) -- These instances are in base-4.3
Control/Monad/Trans/Except.hs view
@@ -79,11 +79,13 @@ -- (The inverse of 'runExcept'). except :: Either e a -> Except e a except m = ExceptT (Identity m)+{-# INLINE except #-}  -- | Extractor for computations in the exception monad. -- (The inverse of 'except'). runExcept :: Except e a -> Either e a runExcept (ExceptT m) = runIdentity m+{-# INLINE runExcept #-}  -- | Map the unwrapped computation using the given function. --@@ -92,11 +94,13 @@         -> Except e a         -> Except e' b mapExcept f = mapExceptT (Identity . f . runIdentity)+{-# INLINE mapExcept #-}  -- | Transform any exceptions thrown by the computation using the given -- function (a specialization of 'withExceptT'). withExcept :: (e -> e') -> Except e a -> Except e' a withExcept = withExceptT+{-# INLINE withExcept #-}  -- | A monad transformer that adds exceptions to other monads. --@@ -113,10 +117,12 @@  instance (Eq e, Eq1 m) => Eq1 (ExceptT e m) where     liftEq eq (ExceptT x) (ExceptT y) = liftEq (liftEq eq) x y+    {-# INLINE liftEq #-}  instance (Ord e, Ord1 m) => Ord1 (ExceptT e m) where     liftCompare comp (ExceptT x) (ExceptT y) =         liftCompare (liftCompare comp) x y+    {-# INLINE liftCompare #-}  instance (Read e, Read1 m) => Read1 (ExceptT e m) where     liftReadsPrec rp rl = readsData $@@ -132,8 +138,10 @@         sp' = liftShowsPrec sp sl         sl' = liftShowList sp sl -instance (Eq e, Eq1 m, Eq a) => Eq (ExceptT e m a) where (==) = eq1-instance (Ord e, Ord1 m, Ord a) => Ord (ExceptT e m a) where compare = compare1+instance (Eq e, Eq1 m, Eq a) => Eq (ExceptT e m a)+    where (==) = eq1+instance (Ord e, Ord1 m, Ord a) => Ord (ExceptT e m a)+    where compare = compare1 instance (Read e, Read1 m, Read a) => Read (ExceptT e m a) where     readsPrec = readsPrec1 instance (Show e, Show1 m, Show a) => Show (ExceptT e m a) where@@ -142,6 +150,7 @@ -- | The inverse of 'ExceptT'. runExceptT :: ExceptT e m a -> m (Either e a) runExceptT (ExceptT m) = m+{-# INLINE runExceptT #-}  -- | Map the unwrapped computation using the given function. --@@ -150,24 +159,30 @@         -> ExceptT e m a         -> ExceptT e' n b mapExceptT f m = ExceptT $ f (runExceptT m)+{-# INLINE mapExceptT #-}  -- | Transform any exceptions thrown by the computation using the -- given function. withExceptT :: (Functor m) => (e -> e') -> ExceptT e m a -> ExceptT e' m a withExceptT f = mapExceptT $ fmap $ either (Left . f) Right+{-# INLINE withExceptT #-}  instance (Functor m) => Functor (ExceptT e m) where     fmap f = ExceptT . fmap (fmap f) . runExceptT+    {-# INLINE fmap #-}  instance (Foldable f) => Foldable (ExceptT e f) where     foldMap f (ExceptT a) = foldMap (either (const mempty) f) a+    {-# INLINE foldMap #-}  instance (Traversable f) => Traversable (ExceptT e f) where     traverse f (ExceptT a) =         ExceptT <$> traverse (either (pure . Left) (fmap Right . f)) a+    {-# INLINE traverse #-}  instance (Functor m, Monad m) => Applicative (ExceptT e m) where     pure a = ExceptT $ return (Right a)+    {-# INLINE pure #-}     ExceptT f <*> ExceptT v = ExceptT $ do         mf <- f         case mf of@@ -177,52 +192,65 @@                 case mv of                     Left e -> return (Left e)                     Right x -> return (Right (k x))+    {-# INLINEABLE (<*>) #-}  instance (Functor m, Monad m, Monoid e) => Alternative (ExceptT e m) where     empty = ExceptT $ return (Left mempty)+    {-# INLINE empty #-}     ExceptT mx <|> ExceptT my = ExceptT $ do         ex <- mx         case ex of             Left e -> liftM (either (Left . mappend e) Right) my             Right x -> return (Right x)+    {-# INLINEABLE (<|>) #-}  instance (Monad m) => Monad (ExceptT e m) where #if !(MIN_VERSION_base(4,8,0))     return a = ExceptT $ return (Right a)+    {-# INLINE return #-} #endif     m >>= k = ExceptT $ do         a <- runExceptT m         case a of             Left e -> return (Left e)             Right x -> runExceptT (k x)+    {-# INLINE (>>=) #-}     fail = ExceptT . fail+    {-# INLINE fail #-}  #if MIN_VERSION_base(4,9,0) instance (Fail.MonadFail m) => Fail.MonadFail (ExceptT e m) where     fail = ExceptT . Fail.fail+    {-# INLINE fail #-} #endif  instance (Monad m, Monoid e) => MonadPlus (ExceptT e m) where     mzero = ExceptT $ return (Left mempty)+    {-# INLINE mzero #-}     ExceptT mx `mplus` ExceptT my = ExceptT $ do         ex <- mx         case ex of             Left e -> liftM (either (Left . mappend e) Right) my             Right x -> return (Right x)+    {-# INLINEABLE mplus #-}  instance (MonadFix m) => MonadFix (ExceptT e m) where     mfix f = ExceptT (mfix (runExceptT . f . either (const bomb) id))       where bomb = error "mfix (ExceptT): inner computation returned Left value"+    {-# INLINE mfix #-}  instance MonadTrans (ExceptT e) where     lift = ExceptT . liftM Right+    {-# INLINE lift #-}  instance (MonadIO m) => MonadIO (ExceptT e m) where     liftIO = lift . liftIO+    {-# INLINE liftIO #-}  #if MIN_VERSION_base(4,4,0) instance (MonadZip m) => MonadZip (ExceptT e m) where     mzipWith f (ExceptT a) (ExceptT b) = ExceptT $ mzipWith (liftA2 f) a b+    {-# INLINE mzipWith #-} #endif  -- | Signal an exception value @e@.@@ -232,6 +260,7 @@ -- * @'throwE' e >>= m = 'throwE' e@ throwE :: (Monad m) => e -> ExceptT e m a throwE = ExceptT . return . Left+{-# INLINE throwE #-}  -- | Handle an exception. --@@ -248,18 +277,21 @@     case a of         Left  l -> runExceptT (h l)         Right r -> return (Right r)+{-# INLINE catchE #-}  -- | Lift a @callCC@ operation to the new monad. liftCallCC :: CallCC m (Either e a) (Either e b) -> CallCC (ExceptT e m) a b liftCallCC callCC f = ExceptT $     callCC $ \ c ->     runExceptT (f (\ a -> ExceptT $ c (Right a)))+{-# INLINE liftCallCC #-}  -- | Lift a @listen@ operation to the new monad. liftListen :: (Monad m) => Listen w m (Either e a) -> Listen w (ExceptT e m) a liftListen listen = mapExceptT $ \ m -> do     (a, w) <- listen m     return $! fmap (\ r -> (r, w)) a+{-# INLINE liftListen #-}  -- | Lift a @pass@ operation to the new monad. liftPass :: (Monad m) => Pass w m (Either e a) -> Pass w (ExceptT e m) a@@ -268,3 +300,4 @@     return $! case a of         Left l -> (Left l, id)         Right (r, f) -> (Right r, f)+{-# INLINE liftPass #-}
Control/Monad/Trans/Identity.hs view
@@ -54,9 +54,11 @@  instance (Eq1 f) => Eq1 (IdentityT f) where     liftEq eq (IdentityT x) (IdentityT y) = liftEq eq x y+    {-# INLINE liftEq #-}  instance (Ord1 f) => Ord1 (IdentityT f) where     liftCompare comp (IdentityT x) (IdentityT y) = liftCompare comp x y+    {-# INLINE liftCompare #-}  instance (Read1 f) => Read1 (IdentityT f) where     liftReadsPrec rp rl = readsData $@@ -73,65 +75,86 @@  instance (Functor m) => Functor (IdentityT m) where     fmap f = mapIdentityT (fmap f)+    {-# INLINE fmap #-}  instance (Foldable f) => Foldable (IdentityT f) where     foldMap f (IdentityT a) = foldMap f a+    {-# INLINE foldMap #-}  instance (Traversable f) => Traversable (IdentityT f) where     traverse f (IdentityT a) = IdentityT <$> traverse f a+    {-# INLINE traverse #-}  instance (Applicative m) => Applicative (IdentityT m) where     pure x = IdentityT (pure x)+    {-# INLINE pure #-}     (<*>) = lift2IdentityT (<*>)+    {-# INLINE (<*>) #-}  instance (Alternative m) => Alternative (IdentityT m) where     empty = IdentityT empty+    {-# INLINE empty #-}     (<|>) = lift2IdentityT (<|>)+    {-# INLINE (<|>) #-}  instance (Monad m) => Monad (IdentityT m) where #if !(MIN_VERSION_base(4,8,0))     return = IdentityT . return+    {-# INLINE return #-} #endif     m >>= k = IdentityT $ runIdentityT . k =<< runIdentityT m+    {-# INLINE (>>=) #-}     fail msg = IdentityT $ fail msg+    {-# INLINE fail #-}  #if MIN_VERSION_base(4,9,0) instance (Fail.MonadFail m) => Fail.MonadFail (IdentityT m) where     fail msg = IdentityT $ Fail.fail msg+    {-# INLINE fail #-} #endif  instance (MonadPlus m) => MonadPlus (IdentityT m) where     mzero = IdentityT mzero+    {-# INLINE mzero #-}     mplus = lift2IdentityT mplus+    {-# INLINE mplus #-}  instance (MonadFix m) => MonadFix (IdentityT m) where     mfix f = IdentityT (mfix (runIdentityT . f))+    {-# INLINE mfix #-}  instance (MonadIO m) => MonadIO (IdentityT m) where     liftIO = IdentityT . liftIO+    {-# INLINE liftIO #-}  #if MIN_VERSION_base(4,4,0) instance (MonadZip m) => MonadZip (IdentityT m) where     mzipWith f = lift2IdentityT (mzipWith f)+    {-# INLINE mzipWith #-} #endif  instance MonadTrans IdentityT where     lift = IdentityT+    {-# INLINE lift #-}  -- | Lift a unary operation to the new monad. mapIdentityT :: (m a -> n b) -> IdentityT m a -> IdentityT n b mapIdentityT f = IdentityT . f . runIdentityT+{-# INLINE mapIdentityT #-}  -- | Lift a binary operation to the new monad. lift2IdentityT ::     (m a -> n b -> p c) -> IdentityT m a -> IdentityT n b -> IdentityT p c lift2IdentityT f a b = IdentityT (f (runIdentityT a) (runIdentityT b))+{-# INLINE lift2IdentityT #-}  -- | Lift a @callCC@ operation to the new monad. liftCallCC :: CallCC m a b -> CallCC (IdentityT m) a b liftCallCC callCC f =     IdentityT $ callCC $ \ c -> runIdentityT (f (IdentityT . c))+{-# INLINE liftCallCC #-}  -- | Lift a @catchE@ operation to the new monad. liftCatch :: Catch e m a -> Catch e (IdentityT m) a liftCatch f m h = IdentityT $ f (runIdentityT m) (runIdentityT . h)+{-# INLINE liftCatch #-}
Control/Monad/Trans/List.hs view
@@ -52,9 +52,11 @@  instance (Eq1 m) => Eq1 (ListT m) where     liftEq eq (ListT x) (ListT y) = liftEq (liftEq eq) x y+    {-# INLINE liftEq #-}  instance (Ord1 m) => Ord1 (ListT m) where     liftCompare comp (ListT x) (ListT y) = liftCompare (liftCompare comp) x y+    {-# INLINE liftCompare #-}  instance (Read1 m) => Read1 (ListT m) where     liftReadsPrec rp rl = readsData $@@ -80,57 +82,74 @@ -- * @'runListT' ('mapListT' f m) = f ('runListT' m)@ mapListT :: (m [a] -> n [b]) -> ListT m a -> ListT n b mapListT f m = ListT $ f (runListT m)+{-# INLINE mapListT #-}  instance (Functor m) => Functor (ListT m) where     fmap f = mapListT $ fmap $ map f+    {-# INLINE fmap #-}  instance (Foldable f) => Foldable (ListT f) where     foldMap f (ListT a) = foldMap (foldMap f) a+    {-# INLINE foldMap #-}  instance (Traversable f) => Traversable (ListT f) where     traverse f (ListT a) = ListT <$> traverse (traverse f) a+    {-# INLINE traverse #-}  instance (Applicative m) => Applicative (ListT m) where     pure a  = ListT $ pure [a]+    {-# INLINE pure #-}     f <*> v = ListT $ (<*>) <$> runListT f <*> runListT v+    {-# INLINE (<*>) #-}  instance (Applicative m) => Alternative (ListT m) where     empty   = ListT $ pure []+    {-# INLINE empty #-}     m <|> n = ListT $ (++) <$> runListT m <*> runListT n+    {-# INLINE (<|>) #-}  instance (Monad m) => Monad (ListT m) where #if !(MIN_VERSION_base(4,8,0))     return a = ListT $ return [a]+    {-# INLINE return #-} #endif     m >>= k  = ListT $ do         a <- runListT m         b <- mapM (runListT . k) a         return (concat b)+    {-# INLINE (>>=) #-}     fail _ = ListT $ return []+    {-# INLINE fail #-}  #if MIN_VERSION_base(4,9,0) instance (Monad m) => Fail.MonadFail (ListT m) where     fail _ = ListT $ return []+    {-# INLINE fail #-} #endif  instance (Monad m) => MonadPlus (ListT m) where     mzero       = ListT $ return []+    {-# INLINE mzero #-}     m `mplus` n = ListT $ do         a <- runListT m         b <- runListT n         return (a ++ b)+    {-# INLINE mplus #-}  instance MonadTrans ListT where     lift m = ListT $ do         a <- m         return [a]+    {-# INLINE lift #-}  instance (MonadIO m) => MonadIO (ListT m) where     liftIO = lift . liftIO+    {-# INLINE liftIO #-}  #if MIN_VERSION_base(4,4,0) instance (MonadZip m) => MonadZip (ListT m) where     mzipWith f (ListT a) (ListT b) = ListT $ mzipWith (zipWith f) a b+    {-# INLINE mzipWith #-} #endif  -- | Lift a @callCC@ operation to the new monad.@@ -138,8 +157,10 @@ liftCallCC callCC f = ListT $     callCC $ \ c ->     runListT (f (\ a -> ListT $ c [a]))+{-# INLINE liftCallCC #-}  -- | Lift a @catchE@ operation to the new monad. liftCatch :: Catch e m [a] -> Catch e (ListT m) a liftCatch catchE m h = ListT $ runListT m     `catchE` \ e -> runListT (h e)+{-# INLINE liftCatch #-}
Control/Monad/Trans/Maybe.hs view
@@ -71,9 +71,11 @@  instance (Eq1 m) => Eq1 (MaybeT m) where     liftEq eq (MaybeT x) (MaybeT y) = liftEq (liftEq eq) x y+    {-# INLINE liftEq #-}  instance (Ord1 m) => Ord1 (MaybeT m) where     liftCompare comp (MaybeT x) (MaybeT y) = liftCompare (liftCompare comp) x y+    {-# INLINE liftCompare #-}  instance (Read1 m) => Read1 (MaybeT m) where     liftReadsPrec rp rl = readsData $@@ -99,28 +101,35 @@ -- * @'runMaybeT' ('mapMaybeT' f m) = f ('runMaybeT' m)@ mapMaybeT :: (m (Maybe a) -> n (Maybe b)) -> MaybeT m a -> MaybeT n b mapMaybeT f = MaybeT . f . runMaybeT+{-# INLINE mapMaybeT #-}  -- | Convert a 'MaybeT' computation to 'ExceptT', with a default -- exception value. maybeToExceptT :: (Functor m) => e -> MaybeT m a -> ExceptT e m a maybeToExceptT e (MaybeT m) = ExceptT $ fmap (maybe (Left e) Right) m+{-# INLINE maybeToExceptT #-}  -- | Convert a 'ExceptT' computation to 'MaybeT', discarding the -- value of any exception. exceptToMaybeT :: (Functor m) => ExceptT e m a -> MaybeT m a exceptToMaybeT (ExceptT m) = MaybeT $ fmap (either (const Nothing) Just) m+{-# INLINE exceptToMaybeT #-}  instance (Functor m) => Functor (MaybeT m) where     fmap f = mapMaybeT (fmap (fmap f))+    {-# INLINE fmap #-}  instance (Foldable f) => Foldable (MaybeT f) where     foldMap f (MaybeT a) = foldMap (foldMap f) a+    {-# INLINE foldMap #-}  instance (Traversable f) => Traversable (MaybeT f) where     traverse f (MaybeT a) = MaybeT <$> traverse (traverse f) a+    {-# INLINE traverse #-}  instance (Functor m, Monad m) => Applicative (MaybeT m) where     pure = lift . return+    {-# INLINE pure #-}     mf <*> mx = MaybeT $ do         mb_f <- runMaybeT mf         case mb_f of@@ -130,68 +139,84 @@                 case mb_x of                     Nothing -> return Nothing                     Just x  -> return (Just (f x))+    {-# INLINE (<*>) #-}  instance (Functor m, Monad m) => Alternative (MaybeT m) where     empty = MaybeT (return Nothing)+    {-# INLINE empty #-}     x <|> y = MaybeT $ do         v <- runMaybeT x         case v of             Nothing -> runMaybeT y             Just _  -> return v+    {-# INLINE (<|>) #-}  instance (Monad m) => Monad (MaybeT m) where #if !(MIN_VERSION_base(4,8,0))     return = lift . return+    {-# INLINE return #-} #endif     x >>= f = MaybeT $ do         v <- runMaybeT x         case v of             Nothing -> return Nothing             Just y  -> runMaybeT (f y)+    {-# INLINE (>>=) #-}     fail _ = MaybeT (return Nothing)+    {-# INLINE fail #-}  #if MIN_VERSION_base(4,9,0) instance (Monad m) => Fail.MonadFail (MaybeT m) where     fail _ = MaybeT (return Nothing)+    {-# INLINE fail #-} #endif  instance (Monad m) => MonadPlus (MaybeT m) where     mzero = MaybeT (return Nothing)+    {-# INLINE mzero #-}     mplus x y = MaybeT $ do         v <- runMaybeT x         case v of             Nothing -> runMaybeT y             Just _  -> return v+    {-# INLINE mplus #-}  instance (MonadFix m) => MonadFix (MaybeT m) where     mfix f = MaybeT (mfix (runMaybeT . f . fromMaybe bomb))       where bomb = error "mfix (MaybeT): inner computation returned Nothing"+    {-# INLINE mfix #-}  instance MonadTrans MaybeT where     lift = MaybeT . liftM Just+    {-# INLINE lift #-}  instance (MonadIO m) => MonadIO (MaybeT m) where     liftIO = lift . liftIO+    {-# INLINE liftIO #-}  #if MIN_VERSION_base(4,4,0) instance (MonadZip m) => MonadZip (MaybeT m) where     mzipWith f (MaybeT a) (MaybeT b) = MaybeT $ mzipWith (liftA2 f) a b+    {-# INLINE mzipWith #-} #endif  -- | Lift a @callCC@ operation to the new monad. liftCallCC :: CallCC m (Maybe a) (Maybe b) -> CallCC (MaybeT m) a b liftCallCC callCC f =     MaybeT $ callCC $ \ c -> runMaybeT (f (MaybeT . c . Just))+{-# INLINE liftCallCC #-}  -- | Lift a @catchE@ operation to the new monad. liftCatch :: Catch e m (Maybe a) -> Catch e (MaybeT m) a liftCatch f m h = MaybeT $ f (runMaybeT m) (runMaybeT . h)+{-# INLINE liftCatch #-}  -- | Lift a @listen@ operation to the new monad. liftListen :: (Monad m) => Listen w m (Maybe a) -> Listen w (MaybeT m) a liftListen listen = mapMaybeT $ \ m -> do     (a, w) <- listen m     return $! fmap (\ r -> (r, w)) a+{-# INLINE liftListen #-}  -- | Lift a @pass@ operation to the new monad. liftPass :: (Monad m) => Pass w m (Maybe a) -> Pass w (MaybeT m) a@@ -200,3 +225,4 @@     return $! case a of         Nothing     -> (Nothing, id)         Just (v, f) -> (Just v, f)+{-# INLINE liftPass #-}
Control/Monad/Trans/RWS/Lazy.hs view
@@ -81,11 +81,13 @@ -- (The inverse of 'runRWS'.) rws :: (r -> s -> (a, s, w)) -> RWS r w s a rws f = RWST (\ r s -> Identity (f r s))+{-# INLINE rws #-}  -- | Unwrap an RWS computation as a function. -- (The inverse of 'rws'.) runRWS :: RWS r w s a -> r -> s -> (a, s, w) runRWS m r s = runIdentity (runRWST m r s)+{-# INLINE runRWS #-}  -- | Evaluate a computation with the given initial state and environment, -- returning the final value and output, discarding the final state.@@ -96,6 +98,7 @@ evalRWS m r s = let     (a, _, w) = runRWS m r s     in (a, w)+{-# INLINE evalRWS #-}  -- | Evaluate a computation with the given initial state and environment, -- returning the final state and output, discarding the final value.@@ -106,6 +109,7 @@ execRWS m r s = let     (_, s', w) = runRWS m r s     in (s', w)+{-# INLINE execRWS #-}  -- | Map the return value, final state and output of a computation using -- the given function.@@ -113,6 +117,7 @@ -- * @'runRWS' ('mapRWS' f m) r s = f ('runRWS' m r s)@ mapRWS :: ((a, s, w) -> (b, s, w')) -> RWS r w s a -> RWS r w' s b mapRWS f = mapRWST (Identity . f . runIdentity)+{-# INLINE mapRWS #-}  -- | @'withRWS' f m@ executes action @m@ with an initial environment -- and state modified by applying @f@.@@ -120,6 +125,7 @@ -- * @'runRWS' ('withRWS' f m) r s = 'uncurry' ('runRWS' m) (f r s)@ withRWS :: (r' -> s -> (r, s)) -> RWS r w s a -> RWS r' w s a withRWS = withRWST+{-# INLINE withRWS #-}  -- --------------------------------------------------------------------------- -- | A monad transformer adding reading an environment of type @r@,@@ -137,6 +143,7 @@ evalRWST m r s = do     ~(a, _, w) <- runRWST m r s     return (a, w)+{-# INLINE evalRWST #-}  -- | Evaluate a computation with the given initial state and environment, -- returning the final state and output, discarding the final value.@@ -148,12 +155,14 @@ execRWST m r s = do     ~(_, s', w) <- runRWST m r s     return (s', w)+{-# INLINE execRWST #-}  -- | Map the inner computation using the given function. -- -- * @'runRWST' ('mapRWST' f m) r s = f ('runRWST' m r s)@ mapRWST :: (m (a, s, w) -> n (b, s, w')) -> RWST r w s m a -> RWST r w' s n b mapRWST f m = RWST $ \ r s -> f (runRWST m r s)+{-# INLINE mapRWST #-}  -- | @'withRWST' f m@ executes action @m@ with an initial environment -- and state modified by applying @f@.@@ -161,51 +170,66 @@ -- * @'runRWST' ('withRWST' f m) r s = 'uncurry' ('runRWST' m) (f r s)@ withRWST :: (r' -> s -> (r, s)) -> RWST r w s m a -> RWST r' w s m a withRWST f m = RWST $ \ r s -> uncurry (runRWST m) (f r s)+{-# INLINE withRWST #-}  instance (Functor m) => Functor (RWST r w s m) where     fmap f m = RWST $ \ r s ->         fmap (\ ~(a, s', w) -> (f a, s', w)) $ runRWST m r s+    {-# INLINE fmap #-}  instance (Monoid w, Functor m, Monad m) => Applicative (RWST r w s m) where     pure a = RWST $ \ _ s -> return (a, s, mempty)+    {-# INLINE pure #-}     RWST mf <*> RWST mx  = RWST $ \ r s -> do         ~(f, s', w)  <- mf r s         ~(x, s'',w') <- mx r s'         return (f x, s'', w `mappend` w')+    {-# INLINE (<*>) #-}  instance (Monoid w, Functor m, MonadPlus m) => Alternative (RWST r w s m) where     empty = RWST $ \ _ _ -> mzero+    {-# INLINE empty #-}     RWST m <|> RWST n = RWST $ \ r s -> m r s `mplus` n r s+    {-# INLINE (<|>) #-}  instance (Monoid w, Monad m) => Monad (RWST r w s m) where #if !(MIN_VERSION_base(4,8,0))     return a = RWST $ \ _ s -> return (a, s, mempty)+    {-# INLINE return #-} #endif     m >>= k  = RWST $ \ r s -> do         ~(a, s', w)  <- runRWST m r s         ~(b, s'',w') <- runRWST (k a) r s'         return (b, s'', w `mappend` w')+    {-# INLINE (>>=) #-}     fail msg = RWST $ \ _ _ -> fail msg+    {-# INLINE fail #-}  #if MIN_VERSION_base(4,9,0) instance (Monoid w, Fail.MonadFail m) => Fail.MonadFail (RWST r w s m) where     fail msg = RWST $ \ _ _ -> Fail.fail msg+    {-# INLINE fail #-} #endif  instance (Monoid w, MonadPlus m) => MonadPlus (RWST r w s m) where     mzero = RWST $ \ _ _ -> mzero+    {-# INLINE mzero #-}     RWST m `mplus` RWST n = RWST $ \ r s -> m r s `mplus` n r s+    {-# INLINE mplus #-}  instance (Monoid w, MonadFix m) => MonadFix (RWST r w s m) where     mfix f = RWST $ \ r s -> mfix $ \ ~(a, _, _) -> runRWST (f a) r s+    {-# INLINE mfix #-}  instance (Monoid w) => MonadTrans (RWST r w s) where     lift m = RWST $ \ _ s -> do         a <- m         return (a, s, mempty)+    {-# INLINE lift #-}  instance (Monoid w, MonadIO m) => MonadIO (RWST r w s m) where     liftIO = lift . liftIO+    {-# INLINE liftIO #-}  -- --------------------------------------------------------------------------- -- Reader operations@@ -213,22 +237,26 @@ -- | Constructor for computations in the reader monad (equivalent to 'asks'). reader :: (Monoid w, Monad m) => (r -> a) -> RWST r w s m a reader = asks+{-# INLINE reader #-}  -- | Fetch the value of the environment. ask :: (Monoid w, Monad m) => RWST r w s m r ask = RWST $ \ r s -> return (r, s, mempty)+{-# INLINE ask #-}  -- | Execute a computation in a modified environment -- -- * @'runRWST' ('local' f m) r s = 'runRWST' m (f r) s@ local :: (r -> r) -> RWST r w s m a -> RWST r w s m a local f m = RWST $ \ r s -> runRWST m (f r) s+{-# INLINE local #-}  -- | Retrieve a function of the current environment. -- -- * @'asks' f = 'liftM' f 'ask'@ asks :: (Monoid w, Monad m) => (r -> a) -> RWST r w s m a asks f = RWST $ \ r s -> return (f r, s, mempty)+{-# INLINE asks #-}  -- --------------------------------------------------------------------------- -- Writer operations@@ -236,10 +264,12 @@ -- | Construct a writer computation from a (result, output) pair. writer :: (Monad m) => (a, w) -> RWST r w s m a writer (a, w) = RWST $ \ _ s -> return (a, s, w)+{-# INLINE writer #-}  -- | @'tell' w@ is an action that produces the output @w@. tell :: (Monad m) => w -> RWST r w s m () tell w = RWST $ \ _ s -> return ((),s,w)+{-# INLINE tell #-}  -- | @'listen' m@ is an action that executes the action @m@ and adds its -- output to the value of the computation.@@ -249,6 +279,7 @@ listen m = RWST $ \ r s -> do     ~(a, s', w) <- runRWST m r s     return ((a, w), s', w)+{-# INLINE listen #-}  -- | @'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.@@ -260,6 +291,7 @@ listens f m = RWST $ \ r s -> do     ~(a, s', w) <- runRWST m r s     return ((a, f w), s', w)+{-# INLINE listens #-}  -- | @'pass' m@ is an action that executes the action @m@, which returns -- a value and a function, and returns the value, applying the function@@ -270,6 +302,7 @@ pass m = RWST $ \ r s -> do     ~((a, f), s', w) <- runRWST m r s     return (a, s', f w)+{-# INLINE pass #-}  -- | @'censor' f m@ is an action that executes the action @m@ and -- applies the function @f@ to its output, leaving the return value@@ -282,6 +315,7 @@ censor f m = RWST $ \ r s -> do     ~(a, s', w) <- runRWST m r s     return (a, s', f w)+{-# INLINE censor #-}  -- --------------------------------------------------------------------------- -- State operations@@ -289,14 +323,17 @@ -- | Construct a state monad computation from a state transformer function. state :: (Monoid w, Monad m) => (s -> (a,s)) -> RWST r w s m a state f = RWST $ \ _ s -> let (a,s') = f s  in  return (a, s', mempty)+{-# INLINE state #-}  -- | Fetch the current value of the state within the monad. get :: (Monoid w, Monad m) => RWST r w s m s get = RWST $ \ _ s -> return (s, s, mempty)+{-# INLINE get #-}  -- | @'put' s@ sets the state within the monad to @s@. put :: (Monoid w, Monad m) => s -> RWST r w s m () put s = RWST $ \ _ _ -> return ((), s, mempty)+{-# INLINE put #-}  -- | @'modify' f@ is an action that updates the state to the result of -- applying @f@ to the current state.@@ -304,6 +341,7 @@ -- * @'modify' f = 'get' >>= ('put' . f)@ modify :: (Monoid w, Monad m) => (s -> s) -> RWST r w s m () modify f = RWST $ \ _ s -> return ((), f s, mempty)+{-# INLINE modify #-}  -- | Get a specific component of the state, using a projection function -- supplied.@@ -311,6 +349,7 @@ -- * @'gets' f = 'liftM' f 'get'@ gets :: (Monoid w, Monad m) => (s -> a) -> RWST r w s m a gets f = RWST $ \ _ s -> return (f s, s, mempty)+{-# INLINE gets #-}  -- | Uniform lifting of a @callCC@ operation to the new monad. -- This version rolls back to the original state on entering the@@ -320,6 +359,7 @@ liftCallCC callCC f = RWST $ \ r s ->     callCC $ \ c ->     runRWST (f (\ a -> RWST $ \ _ _ -> c (a, s, mempty))) r s+{-# INLINE liftCallCC #-}  -- | In-situ lifting of a @callCC@ operation to the new monad. -- This version uses the current state on entering the continuation.@@ -328,8 +368,10 @@ liftCallCC' callCC f = RWST $ \ r s ->     callCC $ \ c ->     runRWST (f (\ a -> RWST $ \ _ s' -> c (a, s', mempty))) r s+{-# INLINE liftCallCC' #-}  -- | Lift a @catchE@ operation to the new monad. liftCatch :: Catch e m (a,s,w) -> Catch e (RWST r w s m) a liftCatch catchE m h =     RWST $ \ r s -> runRWST m r s `catchE` \ e -> runRWST (h e) r s+{-# INLINE liftCatch #-}
Control/Monad/Trans/RWS/Strict.hs view
@@ -81,11 +81,13 @@ -- (The inverse of 'runRWS'.) rws :: (r -> s -> (a, s, w)) -> RWS r w s a rws f = RWST (\ r s -> Identity (f r s))+{-# INLINE rws #-}  -- | Unwrap an RWS computation as a function. -- (The inverse of 'rws'.) runRWS :: RWS r w s a -> r -> s -> (a, s, w) runRWS m r s = runIdentity (runRWST m r s)+{-# INLINE runRWS #-}  -- | Evaluate a computation with the given initial state and environment, -- returning the final value and output, discarding the final state.@@ -96,6 +98,7 @@ evalRWS m r s = let     (a, _, w) = runRWS m r s     in (a, w)+{-# INLINE evalRWS #-}  -- | Evaluate a computation with the given initial state and environment, -- returning the final state and output, discarding the final value.@@ -106,6 +109,7 @@ execRWS m r s = let     (_, s', w) = runRWS m r s     in (s', w)+{-# INLINE execRWS #-}  -- | Map the return value, final state and output of a computation using -- the given function.@@ -113,6 +117,7 @@ -- * @'runRWS' ('mapRWS' f m) r s = f ('runRWS' m r s)@ mapRWS :: ((a, s, w) -> (b, s, w')) -> RWS r w s a -> RWS r w' s b mapRWS f = mapRWST (Identity . f . runIdentity)+{-# INLINE mapRWS #-}  -- | @'withRWS' f m@ executes action @m@ with an initial environment -- and state modified by applying @f@.@@ -120,6 +125,7 @@ -- * @'runRWS' ('withRWS' f m) r s = 'uncurry' ('runRWS' m) (f r s)@ withRWS :: (r' -> s -> (r, s)) -> RWS r w s a -> RWS r' w s a withRWS = withRWST+{-# INLINE withRWS #-}  -- --------------------------------------------------------------------------- -- | A monad transformer adding reading an environment of type @r@,@@ -137,6 +143,7 @@ evalRWST m r s = do     (a, _, w) <- runRWST m r s     return (a, w)+{-# INLINE evalRWST #-}  -- | Evaluate a computation with the given initial state and environment, -- returning the final state and output, discarding the final value.@@ -148,12 +155,14 @@ execRWST m r s = do     (_, s', w) <- runRWST m r s     return (s', w)+{-# INLINE execRWST #-}  -- | Map the inner computation using the given function. -- -- * @'runRWST' ('mapRWST' f m) r s = f ('runRWST' m r s)@ mapRWST :: (m (a, s, w) -> n (b, s, w')) -> RWST r w s m a -> RWST r w' s n b mapRWST f m = RWST $ \ r s -> f (runRWST m r s)+{-# INLINE mapRWST #-}  -- | @'withRWST' f m@ executes action @m@ with an initial environment -- and state modified by applying @f@.@@ -161,51 +170,66 @@ -- * @'runRWST' ('withRWST' f m) r s = 'uncurry' ('runRWST' m) (f r s)@ withRWST :: (r' -> s -> (r, s)) -> RWST r w s m a -> RWST r' w s m a withRWST f m = RWST $ \ r s -> uncurry (runRWST m) (f r s)+{-# INLINE withRWST #-}  instance (Functor m) => Functor (RWST r w s m) where     fmap f m = RWST $ \ r s ->         fmap (\ (a, s', w) -> (f a, s', w)) $ runRWST m r s+    {-# INLINE fmap #-}  instance (Monoid w, Functor m, Monad m) => Applicative (RWST r w s m) where     pure a = RWST $ \ _ s -> return (a, s, mempty)+    {-# INLINE pure #-}     RWST mf <*> RWST mx = RWST $ \ r s -> do         (f, s', w)  <- mf r s         (x, s'',w') <- mx r s'         return (f x, s'', w `mappend` w')+    {-# INLINE (<*>) #-}  instance (Monoid w, Functor m, MonadPlus m) => Alternative (RWST r w s m) where     empty = RWST $ \ _ _ -> mzero+    {-# INLINE empty #-}     RWST m <|> RWST n = RWST $ \ r s -> m r s `mplus` n r s+    {-# INLINE (<|>) #-}  instance (Monoid w, Monad m) => Monad (RWST r w s m) where #if !(MIN_VERSION_base(4,8,0))     return a = RWST $ \ _ s -> return (a, s, mempty)+    {-# INLINE return #-} #endif     m >>= k  = RWST $ \ r s -> do         (a, s', w)  <- runRWST m r s         (b, s'',w') <- runRWST (k a) r s'         return (b, s'', w `mappend` w')+    {-# INLINE (>>=) #-}     fail msg = RWST $ \ _ _ -> fail msg+    {-# INLINE fail #-}  #if MIN_VERSION_base(4,9,0) instance (Monoid w, Fail.MonadFail m) => Fail.MonadFail (RWST r w s m) where     fail msg = RWST $ \ _ _ -> Fail.fail msg+    {-# INLINE fail #-} #endif  instance (Monoid w, MonadPlus m) => MonadPlus (RWST r w s m) where     mzero = RWST $ \ _ _ -> mzero+    {-# INLINE mzero #-}     RWST m `mplus` RWST n = RWST $ \ r s -> m r s `mplus` n r s+    {-# INLINE mplus #-}  instance (Monoid w, MonadFix m) => MonadFix (RWST r w s m) where     mfix f = RWST $ \ r s -> mfix $ \ ~(a, _, _) -> runRWST (f a) r s+    {-# INLINE mfix #-}  instance (Monoid w) => MonadTrans (RWST r w s) where     lift m = RWST $ \ _ s -> do         a <- m         return (a, s, mempty)+    {-# INLINE lift #-}  instance (Monoid w, MonadIO m) => MonadIO (RWST r w s m) where     liftIO = lift . liftIO+    {-# INLINE liftIO #-}  -- --------------------------------------------------------------------------- -- Reader operations@@ -213,22 +237,26 @@ -- | Constructor for computations in the reader monad (equivalent to 'asks'). reader :: (Monoid w, Monad m) => (r -> a) -> RWST r w s m a reader = asks+{-# INLINE reader #-}  -- | Fetch the value of the environment. ask :: (Monoid w, Monad m) => RWST r w s m r ask = RWST $ \ r s -> return (r, s, mempty)+{-# INLINE ask #-}  -- | Execute a computation in a modified environment -- -- * @'runRWST' ('local' f m) r s = 'runRWST' m (f r) s@ local :: (r -> r) -> RWST r w s m a -> RWST r w s m a local f m = RWST $ \ r s -> runRWST m (f r) s+{-# INLINE local #-}  -- | Retrieve a function of the current environment. -- -- * @'asks' f = 'liftM' f 'ask'@ asks :: (Monoid w, Monad m) => (r -> a) -> RWST r w s m a asks f = RWST $ \ r s -> return (f r, s, mempty)+{-# INLINE asks #-}  -- --------------------------------------------------------------------------- -- Writer operations@@ -236,10 +264,12 @@ -- | Construct a writer computation from a (result, output) pair. writer :: (Monad m) => (a, w) -> RWST r w s m a writer (a, w) = RWST $ \ _ s -> return (a, s, w)+{-# INLINE writer #-}  -- | @'tell' w@ is an action that produces the output @w@. tell :: (Monad m) => w -> RWST r w s m () tell w = RWST $ \ _ s -> return ((),s,w)+{-# INLINE tell #-}  -- | @'listen' m@ is an action that executes the action @m@ and adds its -- output to the value of the computation.@@ -249,6 +279,7 @@ listen m = RWST $ \ r s -> do     (a, s', w) <- runRWST m r s     return ((a, w), s', w)+{-# INLINE listen #-}  -- | @'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.@@ -260,6 +291,7 @@ listens f m = RWST $ \ r s -> do     (a, s', w) <- runRWST m r s     return ((a, f w), s', w)+{-# INLINE listens #-}  -- | @'pass' m@ is an action that executes the action @m@, which returns -- a value and a function, and returns the value, applying the function@@ -270,6 +302,7 @@ pass m = RWST $ \ r s -> do     ((a, f), s', w) <- runRWST m r s     return (a, s', f w)+{-# INLINE pass #-}  -- | @'censor' f m@ is an action that executes the action @m@ and -- applies the function @f@ to its output, leaving the return value@@ -282,6 +315,7 @@ censor f m = RWST $ \ r s -> do     (a, s', w) <- runRWST m r s     return (a, s', f w)+{-# INLINE censor #-}  -- --------------------------------------------------------------------------- -- State operations@@ -289,14 +323,17 @@ -- | Construct a state monad computation from a state transformer function. state :: (Monoid w, Monad m) => (s -> (a,s)) -> RWST r w s m a state f = RWST $ \ _ s -> case f s of (a,s') -> return (a, s', mempty)+{-# INLINE state #-}  -- | Fetch the current value of the state within the monad. get :: (Monoid w, Monad m) => RWST r w s m s get = RWST $ \ _ s -> return (s, s, mempty)+{-# INLINE get #-}  -- | @'put' s@ sets the state within the monad to @s@. put :: (Monoid w, Monad m) => s -> RWST r w s m () put s = RWST $ \ _ _ -> return ((), s, mempty)+{-# INLINE put #-}  -- | @'modify' f@ is an action that updates the state to the result of -- applying @f@ to the current state.@@ -304,6 +341,7 @@ -- * @'modify' f = 'get' >>= ('put' . f)@ modify :: (Monoid w, Monad m) => (s -> s) -> RWST r w s m () modify f = RWST $ \ _ s -> return ((), f s, mempty)+{-# INLINE modify #-}  -- | Get a specific component of the state, using a projection function -- supplied.@@ -311,6 +349,7 @@ -- * @'gets' f = 'liftM' f 'get'@ gets :: (Monoid w, Monad m) => (s -> a) -> RWST r w s m a gets f = RWST $ \ _ s -> return (f s, s, mempty)+{-# INLINE gets #-}  -- | Uniform lifting of a @callCC@ operation to the new monad. -- This version rolls back to the original state on entering the@@ -320,6 +359,7 @@ liftCallCC callCC f = RWST $ \ r s ->     callCC $ \ c ->     runRWST (f (\ a -> RWST $ \ _ _ -> c (a, s, mempty))) r s+{-# INLINE liftCallCC #-}  -- | In-situ lifting of a @callCC@ operation to the new monad. -- This version uses the current state on entering the continuation.@@ -328,8 +368,10 @@ liftCallCC' callCC f = RWST $ \ r s ->     callCC $ \ c ->     runRWST (f (\ a -> RWST $ \ _ s' -> c (a, s', mempty))) r s+{-# INLINE liftCallCC' #-}  -- | Lift a @catchE@ operation to the new monad. liftCatch :: Catch e m (a,s,w) -> Catch e (RWST r w s m) a liftCatch catchE m h =     RWST $ \ r s -> runRWST m r s `catchE` \ e -> runRWST (h e) r s+{-# INLINE liftCatch #-}
Control/Monad/Trans/Reader.hs view
@@ -75,20 +75,23 @@ -- | Constructor for computations in the reader monad (equivalent to 'asks'). reader :: (Monad m) => (r -> a) -> ReaderT r m a reader f = ReaderT (return . f)+{-# INLINE reader #-}  -- | Runs a @Reader@ and extracts the final value from it. -- (The inverse of 'reader'.) runReader-     :: Reader r a      -- ^ A @Reader@ to run.+    :: Reader r a       -- ^ A @Reader@ to run.     -> r                -- ^ An initial environment.     -> a runReader m = runIdentity . runReaderT m+{-# INLINE runReader #-}  -- | Transform the value returned by a @Reader@. -- -- * @'runReader' ('mapReader' f m) = f . 'runReader' m@ mapReader :: (a -> b) -> Reader r a -> Reader r b mapReader f = mapReaderT (Identity . f . runIdentity)+{-# INLINE mapReader #-}  -- | Execute a computation in a modified environment -- (a specialization of 'withReaderT').@@ -99,6 +102,7 @@     -> Reader r a       -- ^ Computation to run in the modified environment.     -> Reader r' a withReader = withReaderT+{-# INLINE withReader #-}  -- | The reader monad transformer, -- which adds a read-only environment to the given monad.@@ -112,6 +116,7 @@ -- * @'runReaderT' ('mapReaderT' f m) = f . 'runReaderT' m@ mapReaderT :: (m a -> n b) -> ReaderT r m a -> ReaderT r n b mapReaderT f m = ReaderT $ f . runReaderT m+{-# INLINE mapReaderT #-}  -- | Execute a computation in a modified environment -- (a more general version of 'local').@@ -122,57 +127,75 @@     -> ReaderT r m a    -- ^ Computation to run in the modified environment.     -> ReaderT r' m a withReaderT f m = ReaderT $ runReaderT m . f+{-# INLINE withReaderT #-}  instance (Functor m) => Functor (ReaderT r m) where     fmap f  = mapReaderT (fmap f)+    {-# INLINE fmap #-}  instance (Applicative m) => Applicative (ReaderT r m) where     pure    = liftReaderT . pure+    {-# INLINE pure #-}     f <*> v = ReaderT $ \ r -> runReaderT f r <*> runReaderT v r+    {-# INLINE (<*>) #-}  instance (Alternative m) => Alternative (ReaderT r m) where     empty   = liftReaderT empty+    {-# INLINE empty #-}     m <|> n = ReaderT $ \ r -> runReaderT m r <|> runReaderT n r+    {-# INLINE (<|>) #-}  instance (Monad m) => Monad (ReaderT r m) where #if !(MIN_VERSION_base(4,8,0))     return   = lift . return+    {-# INLINE return #-} #endif     m >>= k  = ReaderT $ \ r -> do         a <- runReaderT m r         runReaderT (k a) r+    {-# INLINE (>>=) #-}     fail msg = lift (fail msg)+    {-# INLINE fail #-}  #if MIN_VERSION_base(4,9,0) instance (Fail.MonadFail m) => Fail.MonadFail (ReaderT r m) where     fail msg = lift (Fail.fail msg)+    {-# INLINE fail #-} #endif  instance (MonadPlus m) => MonadPlus (ReaderT r m) where     mzero       = lift mzero+    {-# INLINE mzero #-}     m `mplus` n = ReaderT $ \ r -> runReaderT m r `mplus` runReaderT n r+    {-# INLINE mplus #-}  instance (MonadFix m) => MonadFix (ReaderT r m) where     mfix f = ReaderT $ \ r -> mfix $ \ a -> runReaderT (f a) r+    {-# INLINE mfix #-}  instance MonadTrans (ReaderT r) where     lift   = liftReaderT+    {-# INLINE lift #-}  instance (MonadIO m) => MonadIO (ReaderT r m) where     liftIO = lift . liftIO+    {-# INLINE liftIO #-}  #if MIN_VERSION_base(4,4,0) instance (MonadZip m) => MonadZip (ReaderT r m) where     mzipWith f (ReaderT m) (ReaderT n) = ReaderT $ \ a ->         mzipWith f (m a) (n a)+    {-# INLINE mzipWith #-} #endif  liftReaderT :: m a -> ReaderT r m a liftReaderT m = ReaderT (const m)+{-# INLINE liftReaderT #-}  -- | Fetch the value of the environment. ask :: (Monad m) => ReaderT r m r ask = ReaderT return+{-# INLINE ask #-}  -- | Execute a computation in a modified environment -- (a specialization of 'withReaderT').@@ -183,6 +206,7 @@     -> ReaderT r m a    -- ^ Computation to run in the modified environment.     -> ReaderT r m a local = withReaderT+{-# INLINE local #-}  -- | Retrieve a function of the current environment. --@@ -191,14 +215,17 @@     => (r -> a)         -- ^ The selector function to apply to the environment.     -> ReaderT r m a asks f = ReaderT (return . f)+{-# INLINE asks #-}  -- | Lift a @callCC@ operation to the new monad. liftCallCC :: CallCC m a b -> CallCC (ReaderT r m) a b liftCallCC callCC f = ReaderT $ \ r ->     callCC $ \ c ->     runReaderT (f (ReaderT . const . c)) r+{-# INLINE liftCallCC #-}  -- | Lift a @catchE@ operation to the new monad. liftCatch :: Catch e m a -> Catch e (ReaderT r m) a liftCatch f m h =     ReaderT $ \ r -> f (runReaderT m r) (\ e -> runReaderT (h e) r)+{-# INLINE liftCatch #-}
Control/Monad/Trans/State/Lazy.hs view
@@ -99,6 +99,7 @@       => (s -> (a, s))  -- ^pure state transformer       -> StateT s m a   -- ^equivalent state-passing computation state f = StateT (return . f)+{-# INLINE state #-}  -- | Unwrap a state monad computation as a function. -- (The inverse of 'state'.)@@ -106,6 +107,7 @@          -> s           -- ^initial state          -> (a, s)      -- ^return value and final state runState m = runIdentity . runStateT m+{-# INLINE runState #-}  -- | Evaluate a state computation with the given initial state -- and return the final value, discarding the final state.@@ -115,6 +117,7 @@           -> s          -- ^initial value           -> a          -- ^return value of the state computation evalState m s = fst (runState m s)+{-# INLINE evalState #-}  -- | Evaluate a state computation with the given initial state -- and return the final state, discarding the final value.@@ -124,6 +127,7 @@           -> s          -- ^initial value           -> s          -- ^final state execState m s = snd (runState m s)+{-# INLINE execState #-}  -- | Map both the return value and final state of a computation using -- the given function.@@ -131,6 +135,7 @@ -- * @'runState' ('mapState' f m) = f . 'runState' m@ mapState :: ((a, s) -> (b, s)) -> State s a -> State s b mapState f = mapStateT (Identity . f . runIdentity)+{-# INLINE mapState #-}  -- | @'withState' f m@ executes action @m@ on a state modified by -- applying @f@.@@ -138,6 +143,7 @@ -- * @'withState' f m = 'modify' f >> m@ withState :: (s -> s) -> State s a -> State s a withState = withStateT+{-# INLINE withState #-}  -- --------------------------------------------------------------------------- -- | A state transformer monad parameterized by:@@ -159,6 +165,7 @@ evalStateT m s = do     ~(a, _) <- runStateT m s     return a+{-# INLINE evalStateT #-}  -- | Evaluate a state computation with the given initial state -- and return the final state, discarding the final value.@@ -168,6 +175,7 @@ execStateT m s = do     ~(_, s') <- runStateT m s     return s'+{-# INLINE execStateT #-}  -- | Map both the return value and final state of a computation using -- the given function.@@ -175,6 +183,7 @@ -- * @'runStateT' ('mapStateT' f m) = f . 'runStateT' m@ mapStateT :: (m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b mapStateT f m = StateT $ f . runStateT m+{-# INLINE mapStateT #-}  -- | @'withStateT' f m@ executes action @m@ on a state modified by -- applying @f@.@@ -182,13 +191,16 @@ -- * @'withStateT' f m = 'modify' f >> m@ withStateT :: (s -> s) -> StateT s m a -> StateT s m a withStateT f m = StateT $ runStateT m . f+{-# INLINE withStateT #-}  instance (Functor m) => Functor (StateT s m) where     fmap f m = StateT $ \ s ->         fmap (\ ~(a, s') -> (f a, s')) $ runStateT m s+    {-# INLINE fmap #-}  instance (Functor m, Monad m) => Applicative (StateT s m) where     pure a = StateT $ \ s -> return (a, s)+    {-# INLINE pure #-}     StateT mf <*> StateT mx = StateT $ \ s -> do         ~(f, s') <- mf s         ~(x, s'') <- mx s'@@ -197,44 +209,57 @@  instance (Functor m, MonadPlus m) => Alternative (StateT s m) where     empty = StateT $ \ _ -> mzero+    {-# INLINE empty #-}     StateT m <|> StateT n = StateT $ \ s -> m s `mplus` n s+    {-# INLINE (<|>) #-}  instance (Monad m) => Monad (StateT s m) where #if !(MIN_VERSION_base(4,8,0))     return a = StateT $ \ s -> return (a, s)+    {-# INLINE return #-} #endif     m >>= k  = StateT $ \ s -> do         ~(a, s') <- runStateT m s         runStateT (k a) s'+    {-# INLINE (>>=) #-}     fail str = StateT $ \ _ -> fail str+    {-# INLINE fail #-}  #if MIN_VERSION_base(4,9,0) instance (Fail.MonadFail m) => Fail.MonadFail (StateT s m) where     fail str = StateT $ \ _ -> Fail.fail str+    {-# INLINE fail #-} #endif  instance (MonadPlus m) => MonadPlus (StateT s m) where     mzero       = StateT $ \ _ -> mzero+    {-# INLINE mzero #-}     StateT m `mplus` StateT n = StateT $ \ s -> m s `mplus` n s+    {-# INLINE mplus #-}  instance (MonadFix m) => MonadFix (StateT s m) where     mfix f = StateT $ \ s -> mfix $ \ ~(a, _) -> runStateT (f a) s+    {-# INLINE mfix #-}  instance MonadTrans (StateT s) where     lift m = StateT $ \ s -> do         a <- m         return (a, s)+    {-# INLINE lift #-}  instance (MonadIO m) => MonadIO (StateT s m) where     liftIO = lift . liftIO+    {-# INLINE liftIO #-}  -- | Fetch the current value of the state within the monad. get :: (Monad m) => StateT s m s get = state $ \ s -> (s, s)+{-# INLINE get #-}  -- | @'put' s@ sets the state within the monad to @s@. put :: (Monad m) => s -> StateT s m () put s = state $ \ _ -> ((), s)+{-# INLINE put #-}  -- | @'modify' f@ is an action that updates the state to the result of -- applying @f@ to the current state.@@ -242,6 +267,7 @@ -- * @'modify' f = 'get' >>= ('put' . f)@ modify :: (Monad m) => (s -> s) -> StateT s m () modify f = state $ \ s -> ((), f s)+{-# INLINE modify #-}  -- | A variant of 'modify' in which the computation is strict in the -- new state.@@ -251,6 +277,7 @@ modify' f = do     s <- get     put $! f s+{-# INLINE modify' #-}  -- | Get a specific component of the state, using a projection function -- supplied.@@ -258,6 +285,7 @@ -- * @'gets' f = 'liftM' f 'get'@ gets :: (Monad m) => (s -> a) -> StateT s m a gets f = state $ \ s -> (f s, s)+{-# INLINE gets #-}  -- | Uniform lifting of a @callCC@ operation to the new monad. -- This version rolls back to the original state on entering the@@ -266,6 +294,7 @@ liftCallCC callCC f = StateT $ \ s ->     callCC $ \ c ->     runStateT (f (\ a -> StateT $ \ _ -> c (a, s))) s+{-# INLINE liftCallCC #-}  -- | In-situ lifting of a @callCC@ operation to the new monad. -- This version uses the current state on entering the continuation.@@ -274,23 +303,27 @@ liftCallCC' callCC f = StateT $ \ s ->     callCC $ \ c ->     runStateT (f (\ a -> StateT $ \ s' -> c (a, s'))) s+{-# INLINE liftCallCC' #-}  -- | Lift a @catchE@ operation to the new monad. liftCatch :: Catch e m (a,s) -> Catch e (StateT s m) a liftCatch catchE m h =     StateT $ \ s -> runStateT m s `catchE` \ e -> runStateT (h e) s+{-# INLINE liftCatch #-}  -- | Lift a @listen@ operation to the new monad. liftListen :: (Monad m) => Listen w m (a,s) -> Listen w (StateT s m) a liftListen listen m = StateT $ \ s -> do     ~((a, s'), w) <- listen (runStateT m s)     return ((a, w), s')+{-# INLINE liftListen #-}  -- | Lift a @pass@ operation to the new monad. liftPass :: (Monad m) => Pass w m (a,s) -> Pass w (StateT s m) a liftPass pass m = StateT $ \ s -> pass $ do     ~((a, f), s') <- runStateT m s     return ((a, s'), f)+{-# INLINE liftPass #-}  {- $examples 
Control/Monad/Trans/State/Strict.hs view
@@ -96,6 +96,7 @@       => (s -> (a, s))  -- ^pure state transformer       -> StateT s m a   -- ^equivalent state-passing computation state f = StateT (return . f)+{-# INLINE state #-}  -- | Unwrap a state monad computation as a function. -- (The inverse of 'state'.)@@ -103,6 +104,7 @@          -> s           -- ^initial state          -> (a, s)      -- ^return value and final state runState m = runIdentity . runStateT m+{-# INLINE runState #-}  -- | Evaluate a state computation with the given initial state -- and return the final value, discarding the final state.@@ -112,6 +114,7 @@           -> s          -- ^initial value           -> a          -- ^return value of the state computation evalState m s = fst (runState m s)+{-# INLINE evalState #-}  -- | Evaluate a state computation with the given initial state -- and return the final state, discarding the final value.@@ -121,6 +124,7 @@           -> s          -- ^initial value           -> s          -- ^final state execState m s = snd (runState m s)+{-# INLINE execState #-}  -- | Map both the return value and final state of a computation using -- the given function.@@ -128,6 +132,7 @@ -- * @'runState' ('mapState' f m) = f . 'runState' m@ mapState :: ((a, s) -> (b, s)) -> State s a -> State s b mapState f = mapStateT (Identity . f . runIdentity)+{-# INLINE mapState #-}  -- | @'withState' f m@ executes action @m@ on a state modified by -- applying @f@.@@ -135,6 +140,7 @@ -- * @'withState' f m = 'modify' f >> m@ withState :: (s -> s) -> State s a -> State s a withState = withStateT+{-# INLINE withState #-}  -- --------------------------------------------------------------------------- -- | A state transformer monad parameterized by:@@ -156,6 +162,7 @@ evalStateT m s = do     (a, _) <- runStateT m s     return a+{-# INLINE evalStateT #-}  -- | Evaluate a state computation with the given initial state -- and return the final state, discarding the final value.@@ -165,6 +172,7 @@ execStateT m s = do     (_, s') <- runStateT m s     return s'+{-# INLINE execStateT #-}  -- | Map both the return value and final state of a computation using -- the given function.@@ -172,6 +180,7 @@ -- * @'runStateT' ('mapStateT' f m) = f . 'runStateT' m@ mapStateT :: (m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b mapStateT f m = StateT $ f . runStateT m+{-# INLINE mapStateT #-}  -- | @'withStateT' f m@ executes action @m@ on a state modified by -- applying @f@.@@ -179,13 +188,16 @@ -- * @'withStateT' f m = 'modify' f >> m@ withStateT :: (s -> s) -> StateT s m a -> StateT s m a withStateT f m = StateT $ runStateT m . f+{-# INLINE withStateT #-}  instance (Functor m) => Functor (StateT s m) where     fmap f m = StateT $ \ s ->         fmap (\ (a, s') -> (f a, s')) $ runStateT m s+    {-# INLINE fmap #-}  instance (Functor m, Monad m) => Applicative (StateT s m) where     pure a = StateT $ \ s -> return (a, s)+    {-# INLINE pure #-}     StateT mf <*> StateT mx = StateT $ \ s -> do         (f, s') <- mf s         (x, s'') <- mx s'@@ -194,44 +206,57 @@  instance (Functor m, MonadPlus m) => Alternative (StateT s m) where     empty = StateT $ \ _ -> mzero+    {-# INLINE empty #-}     StateT m <|> StateT n = StateT $ \ s -> m s `mplus` n s+    {-# INLINE (<|>) #-}  instance (Monad m) => Monad (StateT s m) where #if !(MIN_VERSION_base(4,8,0))     return a = StateT $ \ s -> return (a, s)+    {-# INLINE return #-} #endif     m >>= k  = StateT $ \ s -> do         (a, s') <- runStateT m s         runStateT (k a) s'+    {-# INLINE (>>=) #-}     fail str = StateT $ \ _ -> fail str+    {-# INLINE fail #-}  #if MIN_VERSION_base(4,9,0) instance (Fail.MonadFail m) => Fail.MonadFail (StateT s m) where     fail str = StateT $ \ _ -> Fail.fail str+    {-# INLINE fail #-} #endif  instance (MonadPlus m) => MonadPlus (StateT s m) where     mzero       = StateT $ \ _ -> mzero-    m `mplus` n = StateT $ \ s -> runStateT m s `mplus` runStateT n s+    {-# INLINE mzero #-}+    StateT m `mplus` StateT n = StateT $ \ s -> m s `mplus` n s+    {-# INLINE mplus #-}  instance (MonadFix m) => MonadFix (StateT s m) where     mfix f = StateT $ \ s -> mfix $ \ ~(a, _) -> runStateT (f a) s+    {-# INLINE mfix #-}  instance MonadTrans (StateT s) where     lift m = StateT $ \ s -> do         a <- m         return (a, s)+    {-# INLINE lift #-}  instance (MonadIO m) => MonadIO (StateT s m) where     liftIO = lift . liftIO+    {-# INLINE liftIO #-}  -- | Fetch the current value of the state within the monad. get :: (Monad m) => StateT s m s get = state $ \ s -> (s, s)+{-# INLINE get #-}  -- | @'put' s@ sets the state within the monad to @s@. put :: (Monad m) => s -> StateT s m () put s = state $ \ _ -> ((), s)+{-# INLINE put #-}  -- | @'modify' f@ is an action that updates the state to the result of -- applying @f@ to the current state.@@ -239,6 +264,7 @@ -- * @'modify' f = 'get' >>= ('put' . f)@ modify :: (Monad m) => (s -> s) -> StateT s m () modify f = state $ \ s -> ((), f s)+{-# INLINE modify #-}  -- | A variant of 'modify' in which the computation is strict in the -- new state.@@ -248,6 +274,7 @@ modify' f = do     s <- get     put $! f s+{-# INLINE modify' #-}  -- | Get a specific component of the state, using a projection function -- supplied.@@ -255,6 +282,7 @@ -- * @'gets' f = 'liftM' f 'get'@ gets :: (Monad m) => (s -> a) -> StateT s m a gets f = state $ \ s -> (f s, s)+{-# INLINE gets #-}  -- | Uniform lifting of a @callCC@ operation to the new monad. -- This version rolls back to the original state on entering the@@ -263,6 +291,7 @@ liftCallCC callCC f = StateT $ \ s ->     callCC $ \ c ->     runStateT (f (\ a -> StateT $ \ _ -> c (a, s))) s+{-# INLINE liftCallCC #-}  -- | In-situ lifting of a @callCC@ operation to the new monad. -- This version uses the current state on entering the continuation.@@ -271,23 +300,27 @@ liftCallCC' callCC f = StateT $ \ s ->     callCC $ \ c ->     runStateT (f (\ a -> StateT $ \ s' -> c (a, s'))) s+{-# INLINE liftCallCC' #-}  -- | Lift a @catchE@ operation to the new monad. liftCatch :: Catch e m (a,s) -> Catch e (StateT s m) a liftCatch catchE m h =     StateT $ \ s -> runStateT m s `catchE` \ e -> runStateT (h e) s+{-# INLINE liftCatch #-}  -- | Lift a @listen@ operation to the new monad. liftListen :: (Monad m) => Listen w m (a,s) -> Listen w (StateT s m) a liftListen listen m = StateT $ \ s -> do     ((a, s'), w) <- listen (runStateT m s)     return ((a, w), s')+{-# INLINE liftListen #-}  -- | Lift a @pass@ operation to the new monad. liftPass :: (Monad m) => Pass w m (a,s) -> Pass w (StateT s m) a liftPass pass m = StateT $ \ s -> pass $ do     ((a, f), s') <- runStateT m s     return ((a, s'), f)+{-# INLINE liftPass #-}  {- $examples 
Control/Monad/Trans/Writer/Lazy.hs view
@@ -79,17 +79,20 @@ -- (The inverse of 'runWriter'.) writer :: (Monad m) => (a, w) -> WriterT w m a writer = WriterT . return+{-# INLINE writer #-}  -- | Unwrap a writer computation as a (result, output) pair. -- (The inverse of 'writer'.) runWriter :: Writer w a -> (a, w) runWriter = runIdentity . runWriterT+{-# INLINE runWriter #-}  -- | Extract the output from a writer computation. -- -- * @'execWriter' m = 'snd' ('runWriter' m)@ execWriter :: Writer w a -> w execWriter m = snd (runWriter m)+{-# INLINE execWriter #-}  -- | Map both the return value and output of a computation using -- the given function.@@ -97,6 +100,7 @@ -- * @'runWriter' ('mapWriter' f m) = f ('runWriter' m)@ mapWriter :: ((a, w) -> (b, w')) -> Writer w a -> Writer w' b mapWriter f = mapWriterT (Identity . f . runIdentity)+{-# INLINE mapWriter #-}  -- --------------------------------------------------------------------------- -- | A writer monad parameterized by:@@ -111,10 +115,12 @@  instance (Eq w, Eq1 m) => Eq1 (WriterT w m) where     liftEq eq (WriterT m1) (WriterT m2) = liftEq (liftEq2 eq (==)) m1 m2+    {-# INLINE liftEq #-}  instance (Ord w, Ord1 m) => Ord1 (WriterT w m) where     liftCompare comp (WriterT m1) (WriterT m2) =         liftCompare (liftCompare2 comp compare) m1 m2+    {-# INLINE liftCompare #-}  instance (Read w, Read1 m) => Read1 (WriterT w m) where     liftReadsPrec rp rl = readsData $@@ -144,6 +150,7 @@ execWriterT m = do     ~(_, w) <- runWriterT m     return w+{-# INLINE execWriterT #-}  -- | Map both the return value and output of a computation using -- the given function.@@ -151,65 +158,84 @@ -- * @'runWriterT' ('mapWriterT' f m) = f ('runWriterT' m)@ mapWriterT :: (m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b mapWriterT f m = WriterT $ f (runWriterT m)+{-# INLINE mapWriterT #-}  instance (Functor m) => Functor (WriterT w m) where     fmap f = mapWriterT $ fmap $ \ ~(a, w) -> (f a, w)+    {-# INLINE fmap #-}  instance (Foldable f) => Foldable (WriterT w f) where     foldMap f = foldMap (f . fst) . runWriterT+    {-# INLINE foldMap #-}  instance (Traversable f) => Traversable (WriterT w f) where     traverse f = fmap WriterT . traverse f' . runWriterT where        f' (a, b) = fmap (\ c -> (c, b)) (f a)+    {-# INLINE traverse #-}  instance (Monoid w, Applicative m) => Applicative (WriterT w m) where     pure a  = WriterT $ pure (a, mempty)+    {-# INLINE pure #-}     f <*> v = WriterT $ liftA2 k (runWriterT f) (runWriterT v)       where k ~(a, w) ~(b, w') = (a b, w `mappend` w')+    {-# INLINE (<*>) #-}  instance (Monoid w, Alternative m) => Alternative (WriterT w m) where     empty   = WriterT empty+    {-# INLINE empty #-}     m <|> n = WriterT $ runWriterT m <|> runWriterT n+    {-# INLINE (<|>) #-}  instance (Monoid w, Monad m) => Monad (WriterT w m) where #if !(MIN_VERSION_base(4,8,0))     return a = writer (a, mempty)+    {-# INLINE return #-} #endif     m >>= k  = WriterT $ do         ~(a, w)  <- runWriterT m         ~(b, w') <- runWriterT (k a)         return (b, w `mappend` w')+    {-# INLINE (>>=) #-}     fail msg = WriterT $ fail msg+    {-# INLINE fail #-}  #if MIN_VERSION_base(4,9,0) instance (Monoid w, Fail.MonadFail m) => Fail.MonadFail (WriterT w m) where     fail msg = WriterT $ Fail.fail msg+    {-# INLINE fail #-} #endif  instance (Monoid w, MonadPlus m) => MonadPlus (WriterT w m) where     mzero       = WriterT mzero+    {-# INLINE mzero #-}     m `mplus` n = WriterT $ runWriterT m `mplus` runWriterT n+    {-# INLINE mplus #-}  instance (Monoid w, MonadFix m) => MonadFix (WriterT w m) where     mfix m = WriterT $ mfix $ \ ~(a, _) -> runWriterT (m a)+    {-# INLINE mfix #-}  instance (Monoid w) => MonadTrans (WriterT w) where     lift m = WriterT $ do         a <- m         return (a, mempty)+    {-# INLINE lift #-}  instance (Monoid w, MonadIO m) => MonadIO (WriterT w m) where     liftIO = lift . liftIO+    {-# INLINE liftIO #-}  #if MIN_VERSION_base(4,4,0) instance (Monoid w, MonadZip m) => MonadZip (WriterT w m) where     mzipWith f (WriterT x) (WriterT y) = WriterT $         mzipWith (\ ~(a, w) ~(b, w') -> (f a b, w `mappend` w')) x y+    {-# INLINE mzipWith #-} #endif  -- | @'tell' w@ is an action that produces the output @w@. tell :: (Monad m) => w -> WriterT w m () tell w = writer ((), w)+{-# INLINE tell #-}  -- | @'listen' m@ is an action that executes the action @m@ and adds its -- output to the value of the computation.@@ -219,6 +245,7 @@ listen m = WriterT $ do     ~(a, w) <- runWriterT m     return ((a, w), w)+{-# INLINE listen #-}  -- | @'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.@@ -230,6 +257,7 @@ listens f m = WriterT $ do     ~(a, w) <- runWriterT m     return ((a, f w), w)+{-# INLINE listens #-}  -- | @'pass' m@ is an action that executes the action @m@, which returns -- a value and a function, and returns the value, applying the function@@ -240,6 +268,7 @@ pass m = WriterT $ do     ~((a, f), w) <- runWriterT m     return (a, f w)+{-# INLINE pass #-}  -- | @'censor' f m@ is an action that executes the action @m@ and -- applies the function @f@ to its output, leaving the return value@@ -252,14 +281,17 @@ censor f m = WriterT $ do     ~(a, w) <- runWriterT m     return (a, f w)+{-# INLINE censor #-}  -- | Lift a @callCC@ operation to the new monad. liftCallCC :: (Monoid w) => CallCC m (a,w) (b,w) -> CallCC (WriterT w m) a b liftCallCC callCC f = WriterT $     callCC $ \ c ->     runWriterT (f (\ a -> WriterT $ c (a, mempty)))+{-# INLINE liftCallCC #-}  -- | Lift a @catchE@ operation to the new monad. liftCatch :: Catch e m (a,w) -> Catch e (WriterT w m) a liftCatch catchE m h =     WriterT $ runWriterT m `catchE` \ e -> runWriterT (h e)+{-# INLINE liftCatch #-}
Control/Monad/Trans/Writer/Strict.hs view
@@ -82,17 +82,20 @@ -- (The inverse of 'runWriter'.) writer :: (Monad m) => (a, w) -> WriterT w m a writer = WriterT . return+{-# INLINE writer #-}  -- | Unwrap a writer computation as a (result, output) pair. -- (The inverse of 'writer'.) runWriter :: Writer w a -> (a, w) runWriter = runIdentity . runWriterT+{-# INLINE runWriter #-}  -- | Extract the output from a writer computation. -- -- * @'execWriter' m = 'snd' ('runWriter' m)@ execWriter :: Writer w a -> w execWriter m = snd (runWriter m)+{-# INLINE execWriter #-}  -- | Map both the return value and output of a computation using -- the given function.@@ -100,6 +103,7 @@ -- * @'runWriter' ('mapWriter' f m) = f ('runWriter' m)@ mapWriter :: ((a, w) -> (b, w')) -> Writer w a -> Writer w' b mapWriter f = mapWriterT (Identity . f . runIdentity)+{-# INLINE mapWriter #-}  -- --------------------------------------------------------------------------- -- | A writer monad parameterized by:@@ -114,10 +118,12 @@  instance (Eq w, Eq1 m) => Eq1 (WriterT w m) where     liftEq eq (WriterT m1) (WriterT m2) = liftEq (liftEq2 eq (==)) m1 m2+    {-# INLINE liftEq #-}  instance (Ord w, Ord1 m) => Ord1 (WriterT w m) where     liftCompare comp (WriterT m1) (WriterT m2) =         liftCompare (liftCompare2 comp compare) m1 m2+    {-# INLINE liftCompare #-}  instance (Read w, Read1 m) => Read1 (WriterT w m) where     liftReadsPrec rp rl = readsData $@@ -147,6 +153,7 @@ execWriterT m = do     (_, w) <- runWriterT m     return w+{-# INLINE execWriterT #-}  -- | Map both the return value and output of a computation using -- the given function.@@ -154,65 +161,84 @@ -- * @'runWriterT' ('mapWriterT' f m) = f ('runWriterT' m)@ mapWriterT :: (m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b mapWriterT f m = WriterT $ f (runWriterT m)+{-# INLINE mapWriterT #-}  instance (Functor m) => Functor (WriterT w m) where     fmap f = mapWriterT $ fmap $ \ (a, w) -> (f a, w)+    {-# INLINE fmap #-}  instance (Foldable f) => Foldable (WriterT w f) where     foldMap f = foldMap (f . fst) . runWriterT+    {-# INLINE foldMap #-}  instance (Traversable f) => Traversable (WriterT w f) where     traverse f = fmap WriterT . traverse f' . runWriterT where        f' (a, b) = fmap (\ c -> (c, b)) (f a)+    {-# INLINE traverse #-}  instance (Monoid w, Applicative m) => Applicative (WriterT w m) where     pure a  = WriterT $ pure (a, mempty)+    {-# INLINE pure #-}     f <*> v = WriterT $ liftA2 k (runWriterT f) (runWriterT v)       where k (a, w) (b, w') = (a b, w `mappend` w')+    {-# INLINE (<*>) #-}  instance (Monoid w, Alternative m) => Alternative (WriterT w m) where     empty   = WriterT empty+    {-# INLINE empty #-}     m <|> n = WriterT $ runWriterT m <|> runWriterT n+    {-# INLINE (<|>) #-}  instance (Monoid w, Monad m) => Monad (WriterT w m) where #if !(MIN_VERSION_base(4,8,0))     return a = writer (a, mempty)+    {-# INLINE return #-} #endif     m >>= k  = WriterT $ do         (a, w)  <- runWriterT m         (b, w') <- runWriterT (k a)         return (b, w `mappend` w')+    {-# INLINE (>>=) #-}     fail msg = WriterT $ fail msg+    {-# INLINE fail #-}  #if MIN_VERSION_base(4,9,0) instance (Monoid w, Fail.MonadFail m) => Fail.MonadFail (WriterT w m) where     fail msg = WriterT $ Fail.fail msg+    {-# INLINE fail #-} #endif  instance (Monoid w, MonadPlus m) => MonadPlus (WriterT w m) where     mzero       = WriterT mzero+    {-# INLINE mzero #-}     m `mplus` n = WriterT $ runWriterT m `mplus` runWriterT n+    {-# INLINE mplus #-}  instance (Monoid w, MonadFix m) => MonadFix (WriterT w m) where     mfix m = WriterT $ mfix $ \ ~(a, _) -> runWriterT (m a)+    {-# INLINE mfix #-}  instance (Monoid w) => MonadTrans (WriterT w) where     lift m = WriterT $ do         a <- m         return (a, mempty)+    {-# INLINE lift #-}  instance (Monoid w, MonadIO m) => MonadIO (WriterT w m) where     liftIO = lift . liftIO+    {-# INLINE liftIO #-}  #if MIN_VERSION_base(4,4,0) instance (Monoid w, MonadZip m) => MonadZip (WriterT w m) where     mzipWith f (WriterT x) (WriterT y) = WriterT $         mzipWith (\ (a, w) (b, w') -> (f a b, w `mappend` w')) x y+    {-# INLINE mzipWith #-} #endif  -- | @'tell' w@ is an action that produces the output @w@. tell :: (Monad m) => w -> WriterT w m () tell w = writer ((), w)+{-# INLINE tell #-}  -- | @'listen' m@ is an action that executes the action @m@ and adds its -- output to the value of the computation.@@ -222,6 +248,7 @@ listen m = WriterT $ do     (a, w) <- runWriterT m     return ((a, w), w)+{-# INLINE listen #-}  -- | @'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.@@ -233,6 +260,7 @@ listens f m = WriterT $ do     (a, w) <- runWriterT m     return ((a, f w), w)+{-# INLINE listens #-}  -- | @'pass' m@ is an action that executes the action @m@, which returns -- a value and a function, and returns the value, applying the function@@ -243,6 +271,7 @@ pass m = WriterT $ do     ((a, f), w) <- runWriterT m     return (a, f w)+{-# INLINE pass #-}  -- | @'censor' f m@ is an action that executes the action @m@ and -- applies the function @f@ to its output, leaving the return value@@ -255,14 +284,17 @@ censor f m = WriterT $ do     (a, w) <- runWriterT m     return (a, f w)+{-# INLINE censor #-}  -- | Lift a @callCC@ operation to the new monad. liftCallCC :: (Monoid w) => CallCC m (a,w) (b,w) -> CallCC (WriterT w m) a b liftCallCC callCC f = WriterT $     callCC $ \ c ->     runWriterT (f (\ a -> WriterT $ c (a, mempty)))+{-# INLINE liftCallCC #-}  -- | Lift a @catchE@ operation to the new monad. liftCatch :: Catch e m (a,w) -> Catch e (WriterT w m) a liftCatch catchE m h =     WriterT $ runWriterT m `catchE` \ e -> runWriterT (h e)+{-# INLINE liftCatch #-}
Data/Functor/Constant.hs view
@@ -53,9 +53,11 @@  instance Eq2 Constant where     liftEq2 eq _ (Constant x) (Constant y) = eq x y+    {-# INLINE liftEq2 #-}  instance Ord2 Constant where     liftCompare2 comp _ (Constant x) (Constant y) = comp x y+    {-# INLINE liftCompare2 #-}  instance Read2 Constant where     liftReadsPrec2 rp _ _ _ = readsData $@@ -66,32 +68,45 @@  instance (Eq a) => Eq1 (Constant a) where     liftEq = liftEq2 (==)+    {-# INLINE liftEq #-} instance (Ord a) => Ord1 (Constant a) where     liftCompare = liftCompare2 compare+    {-# INLINE liftCompare #-} instance (Read a) => Read1 (Constant a) where     liftReadsPrec = liftReadsPrec2 readsPrec readList+    {-# INLINE liftReadsPrec #-} instance (Show a) => Show1 (Constant a) where     liftShowsPrec = liftShowsPrec2 showsPrec showList+    {-# INLINE liftShowsPrec #-}  instance Functor (Constant a) where     fmap _ (Constant x) = Constant x+    {-# INLINE fmap #-}  instance Foldable (Constant a) where     foldMap _ (Constant _) = mempty+    {-# INLINE foldMap #-}  instance Traversable (Constant a) where     traverse _ (Constant x) = pure (Constant x)+    {-# INLINE traverse #-}  instance (Monoid a) => Applicative (Constant a) where     pure _ = Constant mempty+    {-# INLINE pure #-}     Constant x <*> Constant y = Constant (x `mappend` y)+    {-# INLINE (<*>) #-}  instance (Monoid a) => Monoid (Constant a b) where     mempty = Constant mempty+    {-# INLINE mempty #-}     Constant x `mappend` Constant y = Constant (x `mappend` y)+    {-# INLINE mappend #-}  #if MIN_VERSION_base(4,8,0) instance Bifunctor Constant where     first f (Constant x) = Constant (f x)+    {-# INLINE first #-}     second _ (Constant x) = Constant x+    {-# INLINE second #-} #endif
Data/Functor/Reverse.hs view
@@ -41,9 +41,11 @@  instance (Eq1 f) => Eq1 (Reverse f) where     liftEq eq (Reverse x) (Reverse y) = liftEq eq x y+    {-# INLINE liftEq #-}  instance (Ord1 f) => Ord1 (Reverse f) where     liftCompare comp (Reverse x) (Reverse y) = liftCompare comp x y+    {-# INLINE liftCompare #-}  instance (Read1 f) => Read1 (Reverse f) where     liftReadsPrec rp rl = readsData $@@ -61,28 +63,40 @@ -- | Derived instance. instance (Functor f) => Functor (Reverse f) where     fmap f (Reverse a) = Reverse (fmap f a)+    {-# INLINE fmap #-}  -- | Derived instance. instance (Applicative f) => Applicative (Reverse f) where     pure a = Reverse (pure a)+    {-# INLINE pure #-}     Reverse f <*> Reverse a = Reverse (f <*> a)+    {-# INLINE (<*>) #-}  -- | Derived instance. instance (Alternative f) => Alternative (Reverse f) where     empty = Reverse empty+    {-# INLINE empty #-}     Reverse x <|> Reverse y = Reverse (x <|> y)+    {-# INLINE (<|>) #-}  -- | Fold from right to left. instance (Foldable f) => Foldable (Reverse f) where     foldMap f (Reverse t) = getDual (foldMap (Dual . f) t)+    {-# INLINE foldMap #-}     foldr f z (Reverse t) = foldl (flip f) z t+    {-# INLINE foldr #-}     foldl f z (Reverse t) = foldr (flip f) z t+    {-# INLINE foldl #-}     foldr1 f (Reverse t) = foldl1 (flip f) t+    {-# INLINE foldr1 #-}     foldl1 f (Reverse t) = foldr1 (flip f) t+    {-# INLINE foldl1 #-}  -- | Traverse from right to left. instance (Traversable f) => Traversable (Reverse f) where     traverse f (Reverse t) =         fmap Reverse . forwards $ traverse (Backwards . f) t+    {-# INLINE traverse #-}     sequenceA (Reverse t) =         fmap Reverse . forwards $ sequenceA (fmap Backwards t)+    {-# INLINE sequenceA #-}
changelog view
@@ -1,5 +1,9 @@ -*-change-log-*- +0.5.2.0 Ross Paterson <R.Paterson@city.ac.uk> Feb 2016+	* Re-added orphan instances for Either to deprecated module+	* Added lots of INLINE pragmas+ 0.5.1.0 Ross Paterson <R.Paterson@city.ac.uk> Jan 2016 	* Bump minor version number, required by added instances 
transformers.cabal view
@@ -1,5 +1,5 @@ name:         transformers-version:      0.5.1.0+version:      0.5.2.0 license:      BSD3 license-file: LICENSE author:       Andy Gill, Ross Paterson