transformers 0.5.6.2 → 0.6.0.0
raw patch · 26 files changed
+293/−577 lines, 26 filesdep ~base
Dependency ranges changed: base
Files
- Control/Applicative/Backwards.hs +23/−2
- Control/Applicative/Lift.hs +16/−8
- Control/Monad/Signatures.hs +4/−4
- Control/Monad/Trans/Accum.hs +8/−1
- Control/Monad/Trans/Class.hs +17/−4
- Control/Monad/Trans/Cont.hs +10/−1
- Control/Monad/Trans/Error.hs +0/−333
- Control/Monad/Trans/Except.hs +37/−2
- Control/Monad/Trans/Identity.hs +10/−1
- Control/Monad/Trans/List.hs +0/−185
- Control/Monad/Trans/Maybe.hs +16/−2
- Control/Monad/Trans/RWS.hs +3/−1
- Control/Monad/Trans/RWS/CPS.hs +11/−2
- Control/Monad/Trans/RWS/Lazy.hs +13/−3
- Control/Monad/Trans/RWS/Strict.hs +13/−2
- Control/Monad/Trans/Reader.hs +10/−3
- Control/Monad/Trans/Select.hs +9/−8
- Control/Monad/Trans/State/Lazy.hs +8/−1
- Control/Monad/Trans/State/Strict.hs +8/−1
- Control/Monad/Trans/Writer/CPS.hs +8/−1
- Control/Monad/Trans/Writer/Lazy.hs +10/−1
- Control/Monad/Trans/Writer/Strict.hs +10/−1
- Data/Functor/Constant.hs +23/−4
- Data/Functor/Reverse.hs +11/−2
- changelog +12/−0
- transformers.cabal +3/−4
Control/Applicative/Backwards.hs view
@@ -1,11 +1,12 @@ {-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Safe #-}+{-# LANGUAGE DeriveGeneric #-} #endif #if __GLASGOW_HASKELL__ >= 706 {-# LANGUAGE PolyKinds #-} #endif-#if __GLASGOW_HASKELL__ >= 710+#if __GLASGOW_HASKELL__ >= 710 && __GLASGOW_HASKELL__ < 802 {-# LANGUAGE AutoDeriveTypeable #-} #endif -----------------------------------------------------------------------------@@ -30,15 +31,23 @@ #if MIN_VERSION_base(4,12,0) import Data.Functor.Contravariant #endif+#if __GLASGOW_HASKELL__ >= 702+import GHC.Generics+#endif import Prelude hiding (foldr, foldr1, foldl, foldl1, null, length) import Control.Applicative import Data.Foldable-import Data.Traversable+#if !(MIN_VERSION_base(4,8,0))+import Data.Traversable (Traversable(traverse, sequenceA))+#endif -- | The same functor, but with an 'Applicative' instance that performs -- actions in the reverse order. newtype Backwards f a = Backwards { forwards :: f a }+#if __GLASGOW_HASKELL__ >= 702+ deriving (Generic, Generic1)+#endif instance (Eq1 f) => Eq1 (Backwards f) where liftEq eq (Backwards x) (Backwards y) = liftEq eq x y@@ -65,6 +74,8 @@ instance (Functor f) => Functor (Backwards f) where fmap f (Backwards a) = Backwards (fmap f a) {-# INLINE fmap #-}+ x <$ Backwards a = Backwards (x <$ a)+ {-# INLINE (<$) #-} -- | Apply @f@-actions in the reverse order. instance (Applicative f) => Applicative (Backwards f) where@@ -72,6 +83,16 @@ {-# INLINE pure #-} Backwards f <*> Backwards a = Backwards (a <**> f) {-# INLINE (<*>) #-}+#if MIN_VERSION_base(4,10,0)+ liftA2 f (Backwards m) (Backwards n) = Backwards $ liftA2 (flip f) n m+ {-# INLINE liftA2 #-}+#endif+#if MIN_VERSION_base(4,2,0)+ Backwards xs *> Backwards ys = Backwards (ys <* xs)+ {-# INLINE (*>) #-}+ Backwards ys <* Backwards xs = Backwards (xs *> ys)+ {-# INLINE (<*) #-}+#endif -- | Try alternatives in the same order as @f@. instance (Alternative f) => Alternative (Backwards f) where
Control/Applicative/Lift.hs view
@@ -1,8 +1,9 @@ {-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Safe #-}+{-# LANGUAGE DeriveGeneric #-} #endif-#if __GLASGOW_HASKELL__ >= 710+#if __GLASGOW_HASKELL__ >= 710 && __GLASGOW_HASKELL__ < 802 {-# LANGUAGE AutoDeriveTypeable #-} #endif -----------------------------------------------------------------------------@@ -34,14 +35,22 @@ import Data.Functor.Classes import Control.Applicative-import Data.Foldable (Foldable(foldMap)) import Data.Functor.Constant+#if !(MIN_VERSION_base(4,8,0))+import Data.Foldable (Foldable(foldMap)) import Data.Monoid (Monoid(..)) import Data.Traversable (Traversable(traverse))+#endif+#if __GLASGOW_HASKELL__ >= 702+import GHC.Generics+#endif -- | Applicative functor formed by adding pure computations to a given -- applicative functor. data Lift f a = Pure a | Other (f a)+#if __GLASGOW_HASKELL__ >= 702+ deriving (Generic, Generic1)+#endif instance (Eq1 f) => Eq1 (Lift f) where liftEq eq (Pure x1) (Pure x2) = eq x1 x2@@ -91,10 +100,8 @@ 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)+ Pure f <*> ax = f <$> ax+ Other f <*> ax = Other (f <*> unLift ax) {-# INLINE (<*>) #-} -- | A combination is 'Pure' only either part is.@@ -131,8 +138,9 @@ -- | An applicative functor that collects a monoid (e.g. lists) of errors. -- A sequence of computations fails if any of its components do, but--- unlike monads made with 'ExceptT' from "Control.Monad.Trans.Except",--- these computations continue after an error, collecting all the errors.+-- unlike monads made with 'Control.Monad.Trans.Except.ExceptT' from+-- "Control.Monad.Trans.Except", these computations continue after an+-- error, collecting all the errors. -- -- * @'pure' f '<*>' 'pure' x = 'pure' (f x)@ --
Control/Monad/Signatures.hs view
@@ -27,7 +27,7 @@ -- introduced in "Control.Monad.Trans.Cont". -- Any lifting function @liftCallCC@ should satisfy ----- * @'lift' (f k) = f' ('lift' . k) => 'lift' (cf f) = liftCallCC cf f'@+-- * @'Control.Monad.Trans.Class.lift' (f k) = f' ('Control.Monad.Trans.Class.lift' . k) => 'Control.Monad.Trans.Class.lift' (cf f) = liftCallCC cf f'@ -- type CallCC m a b = ((a -> m b) -> m a) -> m a @@ -35,7 +35,7 @@ -- introduced in "Control.Monad.Trans.Except". -- Any lifting function @liftCatch@ should satisfy ----- * @'lift' (cf m f) = liftCatch ('lift' . cf) ('lift' f)@+-- * @'Control.Monad.Trans.Class.lift' (cf m f) = liftCatch ('Control.Monad.Trans.Class.lift' . cf) ('Control.Monad.Trans.Class.lift' f)@ -- type Catch e m a = m a -> (e -> m a) -> m a @@ -43,7 +43,7 @@ -- introduced in "Control.Monad.Trans.Writer". -- Any lifting function @liftListen@ should satisfy ----- * @'lift' . liftListen = liftListen . 'lift'@+-- * @'Control.Monad.Trans.Class.lift' . liftListen = liftListen . 'Control.Monad.Trans.Class.lift'@ -- type Listen w m a = m a -> m (a, w) @@ -51,6 +51,6 @@ -- introduced in "Control.Monad.Trans.Writer". -- Any lifting function @liftPass@ should satisfy ----- * @'lift' . liftPass = liftPass . 'lift'@+-- * @'Control.Monad.Trans.Class.lift' . liftPass = liftPass . 'Control.Monad.Trans.Class.lift'@ -- type Pass w m a = m (a, w -> w) -> m a
Control/Monad/Trans/Accum.hs view
@@ -1,8 +1,9 @@ {-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Safe #-}+{-# LANGUAGE DeriveGeneric #-} #endif-#if __GLASGOW_HASKELL__ >= 710+#if __GLASGOW_HASKELL__ >= 710 && __GLASGOW_HASKELL__ < 802 {-# LANGUAGE AutoDeriveTypeable #-} #endif -----------------------------------------------------------------------------@@ -70,6 +71,9 @@ #if !MIN_VERSION_base(4,8,0) import Data.Monoid #endif+#if __GLASGOW_HASKELL__ >= 702+import GHC.Generics+#endif -- --------------------------------------------------------------------------- -- | An accumulation monad parameterized by the type @w@ of output to accumulate.@@ -130,6 +134,9 @@ -- -- * a writer monad transformer with the extra ability to read all previous output. newtype AccumT w m a = AccumT (w -> m (a, w))+#if __GLASGOW_HASKELL__ >= 702+ deriving (Generic)+#endif -- | Unwrap an accumulation computation. runAccumT :: AccumT w m a -> w -> m (a, w)
Control/Monad/Trans/Class.hs view
@@ -2,9 +2,12 @@ #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Safe #-} #endif-#if __GLASGOW_HASKELL__ >= 710+#if __GLASGOW_HASKELL__ >= 710 && __GLASGOW_HASKELL__ < 802 {-# LANGUAGE AutoDeriveTypeable #-} #endif+#if __GLASGOW_HASKELL__ >= 806+{-# LANGUAGE QuantifiedConstraints #-}+#endif ----------------------------------------------------------------------------- -- | -- Module : Control.Monad.Trans.Class@@ -46,14 +49,24 @@ -- $example3 ) where --- | The class of monad transformers. Instances should satisfy the--- following laws, which state that 'lift' is a monad transformation:+-- | The class of monad transformers.+-- For any monad @m@, the result @t m@ should also be a monad,+-- and 'lift' should be a monad transformation from @m@ to @t m@,+-- i.e. it should satisfy the following laws: -- -- * @'lift' . 'return' = 'return'@ -- -- * @'lift' (m >>= f) = 'lift' m >>= ('lift' . f)@-+--+-- Since 0.6.0.0, the requirement that @t m@ be a 'Monad' is enforced+-- by the implication constraint @forall m. 'Monad' m => 'Monad' (t m)@+-- enabled by the @QuantifiedConstraints@ extension (present in GHC 8.6+-- and later).+#if __GLASGOW_HASKELL__ >= 806+class (forall m. Monad m => Monad (t m)) => MonadTrans t where+#else class MonadTrans t where+#endif -- | Lift a computation from the argument monad to the constructed monad. lift :: (Monad m) => m a -> t m a
Control/Monad/Trans/Cont.hs view
@@ -1,11 +1,12 @@ {-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Safe #-}+{-# LANGUAGE DeriveGeneric #-} #endif #if __GLASGOW_HASKELL__ >= 706 {-# LANGUAGE PolyKinds #-} #endif-#if __GLASGOW_HASKELL__ >= 710+#if __GLASGOW_HASKELL__ >= 710 && __GLASGOW_HASKELL__ < 802 {-# LANGUAGE AutoDeriveTypeable #-} #endif -----------------------------------------------------------------------------@@ -52,10 +53,15 @@ import Control.Monad.Trans.Class import Data.Functor.Identity +#if !(MIN_VERSION_base(4,8,0)) import Control.Applicative+#endif #if MIN_VERSION_base(4,9,0) import qualified Control.Monad.Fail as Fail #endif+#if __GLASGOW_HASKELL__ >= 702+import GHC.Generics+#endif {- | Continuation monad.@@ -134,6 +140,9 @@ -- '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 }+#if __GLASGOW_HASKELL__ >= 702+ deriving (Generic)+#endif -- | The result of running a CPS computation with 'return' as the -- final continuation.
− Control/Monad/Trans/Error.hs
@@ -1,333 +0,0 @@-{-# LANGUAGE CPP #-}-#if __GLASGOW_HASKELL__ >= 702-{-# LANGUAGE Safe #-}-#endif-#if __GLASGOW_HASKELL__ >= 710-{-# LANGUAGE AutoDeriveTypeable #-}-#endif-#if !(MIN_VERSION_base(4,9,0))-{-# OPTIONS_GHC -fno-warn-orphans #-}-#endif--------------------------------------------------------------------------------- |--- Module : Control.Monad.Trans.Error--- Copyright : (c) Michael Weber <michael.weber@post.rwth-aachen.de> 2001,--- (c) Jeff Newbern 2003-2006,--- (c) Andriy Palamarchuk 2006--- License : BSD-style (see the file LICENSE)------ Maintainer : R.Paterson@city.ac.uk--- Stability : experimental--- Portability : portable------ This monad transformer adds the ability to fail or throw exceptions--- to a monad.------ A sequence of actions succeeds, producing a value, only if all the--- actions in the sequence are successful. If one fails with an error,--- the rest of the sequence is skipped and the composite action fails--- with that error.------ If the value of the error is not required, the variant in--- "Control.Monad.Trans.Maybe" may be used instead.------ /Note:/ This module will be removed in a future release.--- Instead, use "Control.Monad.Trans.Except", which does not restrict--- the exception type, and also includes a base exception monad.--------------------------------------------------------------------------------module Control.Monad.Trans.Error- {-# DEPRECATED "Use Control.Monad.Trans.Except instead" #-} (- -- * The ErrorT monad transformer- Error(..),- ErrorList(..),- ErrorT(..),- mapErrorT,- -- * Error operations- throwError,- catchError,- -- * Lifting other operations- liftCallCC,- liftListen,- liftPass,- -- * Examples- -- $examples- ) where--import Control.Monad.IO.Class-import Control.Monad.Signatures-import Control.Monad.Trans.Class-import Data.Functor.Classes-#if MIN_VERSION_base(4,12,0)-import Data.Functor.Contravariant-#endif--import Control.Applicative-import Control.Exception (IOException)-import Control.Monad-#if MIN_VERSION_base(4,9,0)-import qualified Control.Monad.Fail as Fail-#endif-import Control.Monad.Fix-#if !(MIN_VERSION_base(4,6,0))-import Control.Monad.Instances () -- deprecated from base-4.6-#endif-import Data.Foldable (Foldable(foldMap))-import Data.Monoid (mempty)-import Data.Traversable (Traversable(traverse))-import System.IO.Error--#if !(MIN_VERSION_base(4,9,0))--- These instances are in base-4.9.0--instance MonadPlus IO where- mzero = ioError (userError "mzero")- m `mplus` n = m `catchIOError` \ _ -> n--instance Alternative IO where- empty = mzero- (<|>) = mplus--# if !(MIN_VERSION_base(4,4,0))--- exported by System.IO.Error from base-4.4-catchIOError :: IO a -> (IOError -> IO a) -> IO a-catchIOError = catch-# endif-#endif--instance (Error e) => Alternative (Either e) where- empty = Left noMsg- Left _ <|> n = n- m <|> _ = m--instance (Error e) => MonadPlus (Either e) where- mzero = Left noMsg- Left _ `mplus` n = n- m `mplus` _ = m--#if !(MIN_VERSION_base(4,3,0))--- These instances are in base-4.3--instance Applicative (Either e) where- pure = Right- Left e <*> _ = Left e- Right f <*> r = fmap f r--instance Monad (Either e) where- return = Right- Left l >>= _ = Left l- Right r >>= k = k r--instance MonadFix (Either e) where- mfix f = let- a = f $ case a of- Right r -> r- _ -> error "empty mfix argument"- in a--#endif /* base to 4.2.0.x */---- | An exception to be thrown.------ Minimal complete definition: 'noMsg' or 'strMsg'.-class Error a where- -- | Creates an exception without a message.- -- The default implementation is @'strMsg' \"\"@.- noMsg :: a- -- | Creates an exception with a message.- -- The default implementation of @'strMsg' s@ is 'noMsg'.- strMsg :: String -> a-- noMsg = strMsg ""- strMsg _ = noMsg--instance Error IOException where- strMsg = userError---- | A string can be thrown as an error.-instance (ErrorList a) => Error [a] where- strMsg = listMsg---- | Workaround so that we can have a Haskell 98 instance @'Error' 'String'@.-class ErrorList a where- listMsg :: String -> [a]--instance ErrorList Char where- listMsg = id---- | The error monad transformer. It can be used to add error handling--- to other monads.------ The @ErrorT@ Monad structure is parameterized over two things:------ * e - The error type.------ * m - The inner monad.------ The 'return' function yields a successful computation, while @>>=@--- sequences two subcomputations, failing on the first error.-newtype ErrorT e m a = ErrorT { runErrorT :: m (Either e a) }--instance (Eq e, Eq1 m) => Eq1 (ErrorT e m) where- liftEq eq (ErrorT x) (ErrorT y) = liftEq (liftEq eq) x y--instance (Ord e, Ord1 m) => Ord1 (ErrorT e m) where- liftCompare comp (ErrorT x) (ErrorT y) = liftCompare (liftCompare comp) x y--instance (Read e, Read1 m) => Read1 (ErrorT e m) where- liftReadsPrec rp rl = readsData $- readsUnaryWith (liftReadsPrec rp' rl') "ErrorT" ErrorT- where- rp' = liftReadsPrec rp rl- rl' = liftReadList rp rl--instance (Show e, Show1 m) => Show1 (ErrorT e m) where- liftShowsPrec sp sl d (ErrorT m) =- showsUnaryWith (liftShowsPrec sp' sl') "ErrorT" d m- where- sp' = liftShowsPrec sp sl- sl' = liftShowList sp sl--instance (Eq e, Eq1 m, Eq a) => Eq (ErrorT e m a) where (==) = eq1-instance (Ord e, Ord1 m, Ord a) => Ord (ErrorT e m a) where compare = compare1-instance (Read e, Read1 m, Read a) => Read (ErrorT e m a) where- readsPrec = readsPrec1-instance (Show e, Show1 m, Show a) => Show (ErrorT e m a) where- showsPrec = showsPrec1---- | Map the unwrapped computation using the given function.------ * @'runErrorT' ('mapErrorT' f m) = f ('runErrorT' m)@-mapErrorT :: (m (Either e a) -> n (Either e' b))- -> ErrorT e m a- -> ErrorT e' n b-mapErrorT f m = ErrorT $ f (runErrorT m)--instance (Functor m) => Functor (ErrorT e m) where- fmap f = ErrorT . fmap (fmap f) . runErrorT--instance (Foldable f) => Foldable (ErrorT e f) where- foldMap f (ErrorT a) = foldMap (either (const mempty) f) a--instance (Traversable f) => Traversable (ErrorT e f) where- traverse f (ErrorT a) =- ErrorT <$> traverse (either (pure . Left) (fmap Right . f)) a--instance (Functor m, 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 (Functor m, Monad m, Error e) => Alternative (ErrorT e m) where- empty = mzero- (<|>) = mplus--instance (Monad m, Error e) => Monad (ErrorT e m) where-#if !(MIN_VERSION_base(4,8,0))- return a = ErrorT $ return (Right a)-#endif- m >>= k = ErrorT $ do- a <- runErrorT m- case a of- Left l -> return (Left l)- Right r -> runErrorT (k r)-#if !(MIN_VERSION_base(4,13,0))- fail msg = ErrorT $ return (Left (strMsg msg))-#endif--#if MIN_VERSION_base(4,9,0)-instance (Monad m, Error e) => Fail.MonadFail (ErrorT e m) where- fail msg = ErrorT $ return (Left (strMsg msg))-#endif--instance (Monad m, Error e) => MonadPlus (ErrorT e m) where- mzero = ErrorT $ return (Left noMsg)- m `mplus` n = ErrorT $ do- a <- runErrorT m- case a of- Left _ -> runErrorT n- Right r -> return (Right r)--instance (MonadFix m, Error e) => MonadFix (ErrorT e m) where- mfix f = ErrorT $ mfix $ \ a -> runErrorT $ f $ case a of- Right r -> r- _ -> error "empty mfix argument"--instance MonadTrans (ErrorT e) where- lift m = ErrorT $ do- a <- m- return (Right a)--instance (Error e, MonadIO m) => MonadIO (ErrorT e m) where- liftIO = lift . liftIO--#if MIN_VERSION_base(4,12,0)-instance Contravariant m => Contravariant (ErrorT e m) where- contramap f = ErrorT . contramap (fmap f) . runErrorT-#endif---- | Signal an error value @e@.------ * @'runErrorT' ('throwError' e) = 'return' ('Left' e)@------ * @'throwError' e >>= m = 'throwError' e@-throwError :: (Monad m) => e -> ErrorT e m a-throwError l = ErrorT $ return (Left l)---- | Handle an error.------ * @'catchError' h ('lift' m) = 'lift' m@------ * @'catchError' h ('throwError' e) = h e@-catchError :: (Monad m) =>- ErrorT e m a -- ^ the inner computation- -> (e -> ErrorT e m a) -- ^ a handler for errors in the inner- -- computation- -> ErrorT e m a-m `catchError` h = ErrorT $ do- a <- runErrorT m- case a of- Left l -> runErrorT (h l)- Right r -> return (Right r)---- | Lift a @callCC@ operation to the new monad.-liftCallCC :: CallCC m (Either e a) (Either e b) -> CallCC (ErrorT e m) a b-liftCallCC callCC f = ErrorT $- callCC $ \ c ->- runErrorT (f (\ a -> ErrorT $ c (Right a)))---- | Lift a @listen@ operation to the new monad.-liftListen :: (Monad m) => Listen w m (Either e a) -> Listen w (ErrorT e m) a-liftListen listen = mapErrorT $ \ m -> do- (a, w) <- listen m- return $! fmap (\ r -> (r, w)) a---- | Lift a @pass@ operation to the new monad.-liftPass :: (Monad m) => Pass w m (Either e a) -> Pass w (ErrorT e m) a-liftPass pass = mapErrorT $ \ m -> pass $ do- a <- m- return $! case a of- Left l -> (Left l, id)- Right (r, f) -> (Right r, f)--{- $examples--Wrapping an IO action that can throw an error @e@:--> type ErrorWithIO e a = ErrorT e IO a-> ==> ErrorT (IO (Either e a))--An IO monad wrapped in @StateT@ inside of @ErrorT@:--> type ErrorAndStateWithIO e s a = ErrorT e (StateT s IO) a-> ==> ErrorT (StateT s IO (Either e a))-> ==> ErrorT (StateT (s -> IO (Either e a,s)))---}
Control/Monad/Trans/Except.hs view
@@ -1,8 +1,9 @@ {-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Safe #-}+{-# LANGUAGE DeriveGeneric #-} #endif-#if __GLASGOW_HASKELL__ >= 710+#if __GLASGOW_HASKELL__ >= 710 && __GLASGOW_HASKELL__ < 802 {-# LANGUAGE AutoDeriveTypeable #-} #endif -----------------------------------------------------------------------------@@ -41,6 +42,9 @@ -- * Exception operations throwE, catchE,+ handleE,+ tryE,+ finallyE, -- * Lifting other operations liftCallCC, liftListen,@@ -65,9 +69,14 @@ #if MIN_VERSION_base(4,4,0) import Control.Monad.Zip (MonadZip(mzipWith)) #endif+#if !(MIN_VERSION_base(4,8,0)) import Data.Foldable (Foldable(foldMap))-import Data.Monoid+import Data.Monoid (Monoid(mempty, mappend)) import Data.Traversable (Traversable(traverse))+#endif+#if __GLASGOW_HASKELL__ >= 702+import GHC.Generics+#endif -- | The parameterizable exception monad. --@@ -117,6 +126,9 @@ -- value, while @>>=@ sequences two subcomputations, exiting on the -- first exception. newtype ExceptT e m a = ExceptT (m (Either e a))+#if __GLASGOW_HASKELL__ >= 702+ deriving (Generic, Generic1)+#endif instance (Eq e, Eq1 m) => Eq1 (ExceptT e m) where liftEq eq (ExceptT x) (ExceptT y) = liftEq (liftEq eq) x y@@ -291,6 +303,29 @@ Left l -> runExceptT (h l) Right r -> return (Right r) {-# INLINE catchE #-}++-- | The same as @'flip' 'catchE'@, which is useful in situations where+-- the code for the handler is shorter.+handleE :: Monad m => (e -> ExceptT e' m a) -> ExceptT e m a -> ExceptT e' m a+handleE = flip catchE+{-# INLINE handleE #-}++-- | Similar to 'catchE', but returns an 'Either' result which is+-- @('Right' a)@ if no exception was thown, or @('Left' ex)@ if an+-- exception @ex@ was thrown.+tryE :: Monad m => ExceptT e m a -> ExceptT e m (Either e a)+tryE m = catchE (liftM Right m) (return . Left)+{-# INLINE tryE #-}++-- | @'finallyE' a b@ executes computation @a@ followed by computation @b@,+-- even if @a@ exits early by throwing an exception. In the latter case,+-- the exception is re-thrown after @b@ has been executed.+finallyE :: Monad m => ExceptT e m a -> ExceptT e m () -> ExceptT e m a+finallyE m closer = do+ res <- tryE m+ closer+ either throwE pure res+{-# INLINE finallyE #-} -- | Lift a @callCC@ operation to the new monad. liftCallCC :: CallCC m (Either e a) (Either e b) -> CallCC (ExceptT e m) a b
Control/Monad/Trans/Identity.hs view
@@ -1,11 +1,12 @@ {-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Safe #-}+{-# LANGUAGE DeriveGeneric #-} #endif #if __GLASGOW_HASKELL__ >= 706 {-# LANGUAGE PolyKinds #-} #endif-#if __GLASGOW_HASKELL__ >= 710+#if __GLASGOW_HASKELL__ >= 710 && __GLASGOW_HASKELL__ < 802 {-# LANGUAGE AutoDeriveTypeable #-} #endif -----------------------------------------------------------------------------@@ -50,11 +51,19 @@ import Control.Monad.Zip (MonadZip(mzipWith)) #endif import Data.Foldable+#if !(MIN_VERSION_base(4,8,0)) import Data.Traversable (Traversable(traverse))+#endif import Prelude hiding (foldr, foldr1, foldl, foldl1, null, length)+#if __GLASGOW_HASKELL__ >= 702+import GHC.Generics+#endif -- | The trivial monad transformer, which maps a monad to an equivalent monad. newtype IdentityT f a = IdentityT { runIdentityT :: f a }+#if __GLASGOW_HASKELL__ >= 702+ deriving (Generic, Generic1)+#endif instance (Eq1 f) => Eq1 (IdentityT f) where liftEq eq (IdentityT x) (IdentityT y) = liftEq eq x y
− Control/Monad/Trans/List.hs
@@ -1,185 +0,0 @@-{-# LANGUAGE CPP #-}-#if __GLASGOW_HASKELL__ >= 702-{-# LANGUAGE Safe #-}-#endif-#if __GLASGOW_HASKELL__ >= 710-{-# LANGUAGE AutoDeriveTypeable #-}-#endif--------------------------------------------------------------------------------- |--- Module : Control.Monad.Trans.List--- Copyright : (c) Andy Gill 2001,--- (c) Oregon Graduate Institute of Science and Technology, 2001--- License : BSD-style (see the file LICENSE)------ Maintainer : R.Paterson@city.ac.uk--- Stability : experimental--- Portability : portable------ The ListT monad transformer, adding backtracking to a given monad,--- which must be commutative.--------------------------------------------------------------------------------module Control.Monad.Trans.List- {-# DEPRECATED "This transformer is invalid on most monads" #-} (- -- * The ListT monad transformer- ListT(..),- mapListT,- -- * Lifting other operations- liftCallCC,- liftCatch,- ) where--import Control.Monad.IO.Class-import Control.Monad.Signatures-import Control.Monad.Trans.Class-import Data.Functor.Classes-#if MIN_VERSION_base(4,12,0)-import Data.Functor.Contravariant-#endif--import Control.Applicative-import Control.Monad-#if MIN_VERSION_base(4,9,0)-import qualified Control.Monad.Fail as Fail-#endif-import Control.Monad.Fix-#if MIN_VERSION_base(4,4,0)-import Control.Monad.Zip (MonadZip(mzipWith))-#endif-import Data.Foldable (Foldable(foldMap))-import Data.Traversable (Traversable(traverse))---- | Parameterizable list monad, with an inner monad.------ /Note:/ this does not yield a monad unless the argument monad is commutative.-newtype ListT m a = ListT { runListT :: m [a] }--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 $- readsUnaryWith (liftReadsPrec rp' rl') "ListT" ListT- where- rp' = liftReadsPrec rp rl- rl' = liftReadList rp rl--instance (Show1 m) => Show1 (ListT m) where- liftShowsPrec sp sl d (ListT m) =- showsUnaryWith (liftShowsPrec sp' sl') "ListT" d m- where- sp' = liftShowsPrec sp sl- sl' = liftShowList sp sl--instance (Eq1 m, Eq a) => Eq (ListT m a) where (==) = eq1-instance (Ord1 m, Ord a) => Ord (ListT m a) where compare = compare1-instance (Read1 m, Read a) => Read (ListT m a) where readsPrec = readsPrec1-instance (Show1 m, Show a) => Show (ListT m a) where showsPrec = showsPrec1---- | Map between 'ListT' computations.------ * @'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 (>>=) #-}-#if !(MIN_VERSION_base(4,13,0))- fail _ = ListT $ return []- {-# INLINE fail #-}-#endif--#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 (MonadFix m) => MonadFix (ListT m) where- mfix f = ListT $ mfix (runListT . f . head) >>= \ xs -> case xs of- [] -> return []- x:_ -> liftM (x:) (runListT (mfix (mapListT (liftM tail) . f)))- {-# INLINE mfix #-}--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--#if MIN_VERSION_base(4,12,0)-instance Contravariant m => Contravariant (ListT m) where- contramap f = ListT . contramap (fmap f) . runListT- {-# INLINE contramap #-}-#endif---- | Lift a @callCC@ operation to the new monad.-liftCallCC :: CallCC m [a] [b] -> CallCC (ListT m) a b-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
@@ -1,8 +1,9 @@ {-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Safe #-}+{-# LANGUAGE DeriveGeneric #-} #endif-#if __GLASGOW_HASKELL__ >= 710+#if __GLASGOW_HASKELL__ >= 710 && __GLASGOW_HASKELL__ < 802 {-# LANGUAGE AutoDeriveTypeable #-} #endif -----------------------------------------------------------------------------@@ -31,6 +32,7 @@ MaybeT(..), mapMaybeT, -- * Monad transformations+ hoistMaybe, maybeToExceptT, exceptToMaybeT, -- * Lifting other operations@@ -58,9 +60,14 @@ #if MIN_VERSION_base(4,4,0) import Control.Monad.Zip (MonadZip(mzipWith)) #endif-import Data.Foldable (Foldable(foldMap)) import Data.Maybe (fromMaybe)+#if !(MIN_VERSION_base(4,8,0))+import Data.Foldable (Foldable(foldMap)) import Data.Traversable (Traversable(traverse))+#endif+#if __GLASGOW_HASKELL__ >= 702+import GHC.Generics+#endif -- | The parameterizable maybe monad, obtained by composing an arbitrary -- monad with the 'Maybe' monad.@@ -71,6 +78,9 @@ -- value, while @>>=@ sequences two subcomputations, exiting if either -- computation does. newtype MaybeT m a = MaybeT { runMaybeT :: m (Maybe a) }+#if __GLASGOW_HASKELL__ >= 702+ deriving (Generic, Generic1)+#endif instance (Eq1 m) => Eq1 (MaybeT m) where liftEq eq (MaybeT x) (MaybeT y) = liftEq (liftEq eq) x y@@ -105,6 +115,10 @@ mapMaybeT :: (m (Maybe a) -> n (Maybe b)) -> MaybeT m a -> MaybeT n b mapMaybeT f = MaybeT . f . runMaybeT {-# INLINE mapMaybeT #-}++-- | Convert a 'Maybe' computation to 'MaybeT'.+hoistMaybe :: (Applicative m) => Maybe b -> MaybeT m b+hoistMaybe = MaybeT . pure -- | Convert a 'MaybeT' computation to 'ExceptT', with a default -- exception value.
Control/Monad/Trans/RWS.hs view
@@ -13,7 +13,9 @@ -- Stability : experimental -- Portability : portable ----- A monad transformer that combines 'ReaderT', 'WriterT' and 'StateT'.+-- A monad transformer that combines 'Control.Monad.Trans.Reader.ReaderT',+-- 'Control.Monad.Trans.Writer.Lazy.WriterT' and+-- 'Control.Monad.Trans.State.Lazy.StateT'. -- This version is lazy; for a constant-space version with almost the -- same interface, see "Control.Monad.Trans.RWS.CPS". -----------------------------------------------------------------------------
Control/Monad/Trans/RWS/CPS.hs view
@@ -1,8 +1,9 @@ {-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Safe #-}+{-# LANGUAGE DeriveGeneric #-} #endif-#if __GLASGOW_HASKELL__ >= 710+#if __GLASGOW_HASKELL__ >= 710 && __GLASGOW_HASKELL__ < 802 {-# LANGUAGE AutoDeriveTypeable #-} #endif -----------------------------------------------------------------------------@@ -17,7 +18,9 @@ -- Stability : experimental -- Portability : portable ----- A monad transformer that combines 'ReaderT', 'WriterT' and 'StateT'.+-- A monad transformer that combines 'Control.Monad.Trans.Reader.ReaderT',+-- 'Control.Monad.Trans.Writer.CPS.WriterT' and+-- 'Control.Monad.Trans.State.Strict.StateT'. -- This version uses continuation-passing-style for the writer part -- to achieve constant space usage. -- For a lazy version with the same interface,@@ -80,6 +83,9 @@ #if MIN_VERSION_base(4,9,0) import qualified Control.Monad.Fail as Fail #endif+#if __GLASGOW_HASKELL__ >= 702+import GHC.Generics+#endif -- | A monad containing an environment of type @r@, output of type @w@ -- and an updatable state of type @s@.@@ -143,6 +149,9 @@ -- collecting an output of type @w@ and updating a state of type @s@ -- to an inner monad @m@. newtype RWST r w s m a = RWST { unRWST :: r -> s -> w -> m (a, s, w) }+#if __GLASGOW_HASKELL__ >= 702+ deriving (Generic)+#endif -- | Construct an RWST computation from a function. -- (The inverse of 'runRWST'.)
Control/Monad/Trans/RWS/Lazy.hs view
@@ -1,8 +1,9 @@ {-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Safe #-}+{-# LANGUAGE DeriveGeneric #-} #endif-#if __GLASGOW_HASKELL__ >= 710+#if __GLASGOW_HASKELL__ >= 710 && __GLASGOW_HASKELL__ < 802 {-# LANGUAGE AutoDeriveTypeable #-} #endif -----------------------------------------------------------------------------@@ -16,7 +17,9 @@ -- Stability : experimental -- Portability : portable ----- A monad transformer that combines 'ReaderT', 'WriterT' and 'StateT'.+-- A monad transformer that combines 'Control.Monad.Trans.Reader.ReaderT',+-- 'Control.Monad.Trans.Writer.Lazy.WriterT' and+-- 'Control.Monad.Trans.State.Lazy.StateT'. -- This version is lazy; for a constant-space version with almost the -- same interface, see "Control.Monad.Trans.RWS.CPS". -----------------------------------------------------------------------------@@ -74,7 +77,12 @@ import qualified Control.Monad.Fail as Fail #endif import Control.Monad.Fix+#if !(MIN_VERSION_base(4,8,0)) import Data.Monoid+#endif+#if __GLASGOW_HASKELL__ >= 702+import GHC.Generics+#endif -- | A monad containing an environment of type @r@, output of type @w@ -- and an updatable state of type @s@.@@ -135,7 +143,9 @@ -- collecting an output of type @w@ and updating a state of type @s@ -- to an inner monad @m@. newtype RWST r w s m a = RWST { runRWST :: r -> s -> m (a, s, w) }-+#if __GLASGOW_HASKELL__ >= 702+ deriving (Generic)+#endif -- | Evaluate a computation with the given initial state and environment, -- returning the final value and output, discarding the final state. evalRWST :: (Monad m)
Control/Monad/Trans/RWS/Strict.hs view
@@ -1,8 +1,9 @@ {-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Safe #-}+{-# LANGUAGE DeriveGeneric #-} #endif-#if __GLASGOW_HASKELL__ >= 710+#if __GLASGOW_HASKELL__ >= 710 && __GLASGOW_HASKELL__ < 802 {-# LANGUAGE AutoDeriveTypeable #-} #endif -----------------------------------------------------------------------------@@ -16,7 +17,9 @@ -- Stability : experimental -- Portability : portable ----- A monad transformer that combines 'ReaderT', 'WriterT' and 'StateT'.+-- A monad transformer that combines 'Control.Monad.Trans.Reader.ReaderT',+-- 'Control.Monad.Trans.Writer.Strict.WriterT' and+-- 'Control.Monad.Trans.State.Strict.StateT'. -- This version is strict; for a lazy version with the same interface, -- see "Control.Monad.Trans.RWS.Lazy". -- Although the output is built strictly, it is not possible to@@ -77,7 +80,12 @@ import qualified Control.Monad.Fail as Fail #endif import Control.Monad.Fix+#if !(MIN_VERSION_base(4,8,0)) import Data.Monoid+#endif+#if __GLASGOW_HASKELL__ >= 702+import GHC.Generics+#endif -- | A monad containing an environment of type @r@, output of type @w@ -- and an updatable state of type @s@.@@ -138,6 +146,9 @@ -- collecting an output of type @w@ and updating a state of type @s@ -- to an inner monad @m@. newtype RWST r w s m a = RWST { runRWST :: r -> s -> m (a, s, w) }+#if __GLASGOW_HASKELL__ >= 702+ deriving (Generic)+#endif -- | Evaluate a computation with the given initial state and environment, -- returning the final value and output, discarding the final state.
Control/Monad/Trans/Reader.hs view
@@ -1,8 +1,9 @@ {-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Safe #-}+{-# LANGUAGE DeriveGeneric #-} #endif-#if __GLASGOW_HASKELL__ >= 710+#if __GLASGOW_HASKELL__ >= 710 && __GLASGOW_HASKELL__ < 802 {-# LANGUAGE AutoDeriveTypeable #-} #endif -----------------------------------------------------------------------------@@ -63,9 +64,12 @@ #if MIN_VERSION_base(4,4,0) import Control.Monad.Zip (MonadZip(mzipWith)) #endif-#if MIN_VERSION_base(4,2,0)-import Data.Functor(Functor(..))+#if (MIN_VERSION_base(4,2,0)) && !(MIN_VERSION_base(4,8,0))+import Data.Functor ((<$)) #endif+#if __GLASGOW_HASKELL__ >= 702+import GHC.Generics+#endif -- | The parameterizable reader monad. --@@ -113,6 +117,9 @@ -- The 'return' function ignores the environment, while @>>=@ passes -- the inherited environment to both subcomputations. newtype ReaderT r m a = ReaderT { runReaderT :: r -> m a }+#if __GLASGOW_HASKELL__ >= 702+ deriving (Generic, Generic1)+#endif -- | Transform the computation inside a @ReaderT@. --
Control/Monad/Trans/Select.hs view
@@ -1,11 +1,12 @@ {-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Safe #-}+{-# LANGUAGE DeriveGeneric #-} #endif #if __GLASGOW_HASKELL__ >= 706 {-# LANGUAGE PolyKinds #-} #endif-#if __GLASGOW_HASKELL__ >= 710+#if __GLASGOW_HASKELL__ >= 710 && __GLASGOW_HASKELL__ < 802 {-# LANGUAGE AutoDeriveTypeable #-} #endif -----------------------------------------------------------------------------@@ -41,7 +42,6 @@ mapSelectT, -- * Monad transformation selectToContT,- selectToCont, ) where import Control.Monad.IO.Class@@ -54,6 +54,9 @@ import qualified Control.Monad.Fail as Fail #endif import Data.Functor.Identity+#if __GLASGOW_HASKELL__ >= 702+import GHC.Generics+#endif -- | Selection monad. type Select r = SelectT r Identity@@ -81,6 +84,9 @@ -- 'SelectT' is not a functor on the category of monads, and many operations -- cannot be lifted through it. newtype SelectT r m a = SelectT ((a -> m r) -> m a)+#if __GLASGOW_HASKELL__ >= 702+ deriving (Generic)+#endif -- | Runs a @SelectT@ computation with a function for evaluating answers -- to select a particular answer. (The inverse of 'select'.)@@ -153,9 +159,4 @@ -- | Convert a selection computation to a continuation-passing computation. selectToContT :: (Monad m) => SelectT r m a -> ContT r m a selectToContT (SelectT g) = ContT $ \ k -> g k >>= k-{-# INLINE selectToCont #-}---- | Deprecated name for 'selectToContT'.-{-# DEPRECATED selectToCont "Use selectToContT instead" #-}-selectToCont :: (Monad m) => SelectT r m a -> ContT r m a-selectToCont = selectToContT+{-# INLINE selectToContT #-}
Control/Monad/Trans/State/Lazy.hs view
@@ -1,8 +1,9 @@ {-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Safe #-}+{-# LANGUAGE DeriveGeneric #-} #endif-#if __GLASGOW_HASKELL__ >= 710+#if __GLASGOW_HASKELL__ >= 710 && __GLASGOW_HASKELL__ < 802 {-# LANGUAGE AutoDeriveTypeable #-} #endif -----------------------------------------------------------------------------@@ -87,6 +88,9 @@ import qualified Control.Monad.Fail as Fail #endif import Control.Monad.Fix+#if __GLASGOW_HASKELL__ >= 702+import GHC.Generics+#endif -- --------------------------------------------------------------------------- -- | A state monad parameterized by the type @s@ of the state to carry.@@ -159,6 +163,9 @@ -- the final state of the first computation as the initial state of -- the second. newtype StateT s m a = StateT { runStateT :: s -> m (a,s) }+#if __GLASGOW_HASKELL__ >= 702+ deriving (Generic)+#endif -- | Evaluate a state computation with the given initial state -- and return the final value, discarding the final state.
Control/Monad/Trans/State/Strict.hs view
@@ -1,8 +1,9 @@ {-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Safe #-}+{-# LANGUAGE DeriveGeneric #-} #endif-#if __GLASGOW_HASKELL__ >= 710+#if __GLASGOW_HASKELL__ >= 710 && __GLASGOW_HASKELL__ < 802 {-# LANGUAGE AutoDeriveTypeable #-} #endif -----------------------------------------------------------------------------@@ -84,6 +85,9 @@ import qualified Control.Monad.Fail as Fail #endif import Control.Monad.Fix+#if __GLASGOW_HASKELL__ >= 702+import GHC.Generics+#endif -- --------------------------------------------------------------------------- -- | A state monad parameterized by the type @s@ of the state to carry.@@ -156,6 +160,9 @@ -- the final state of the first computation as the initial state of -- the second. newtype StateT s m a = StateT { runStateT :: s -> m (a,s) }+#if __GLASGOW_HASKELL__ >= 702+ deriving (Generic)+#endif -- | Evaluate a state computation with the given initial state -- and return the final value, discarding the final state.
Control/Monad/Trans/Writer/CPS.hs view
@@ -1,8 +1,9 @@ {-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Safe #-}+{-# LANGUAGE DeriveGeneric #-} #endif-#if __GLASGOW_HASKELL__ >= 710+#if __GLASGOW_HASKELL__ >= 710 && __GLASGOW_HASKELL__ < 802 {-# LANGUAGE AutoDeriveTypeable #-} #endif -----------------------------------------------------------------------------@@ -68,6 +69,9 @@ #if MIN_VERSION_base(4,9,0) import qualified Control.Monad.Fail as Fail #endif+#if __GLASGOW_HASKELL__ >= 702+import GHC.Generics+#endif -- --------------------------------------------------------------------------- -- | A writer monad parameterized by the type @w@ of output to accumulate.@@ -116,6 +120,9 @@ -- combines the outputs of the subcomputations using 'mappend'. newtype WriterT w m a = WriterT { unWriterT :: w -> m (a, w) }+#if __GLASGOW_HASKELL__ >= 702+ deriving (Generic)+#endif -- | Construct a writer computation from a (result, output) computation. -- (The inverse of 'runWriterT'.)
Control/Monad/Trans/Writer/Lazy.hs view
@@ -1,8 +1,9 @@ {-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Safe #-}+{-# LANGUAGE DeriveGeneric #-} #endif-#if __GLASGOW_HASKELL__ >= 710+#if __GLASGOW_HASKELL__ >= 710 && __GLASGOW_HASKELL__ < 802 {-# LANGUAGE AutoDeriveTypeable #-} #endif -----------------------------------------------------------------------------@@ -69,8 +70,13 @@ #endif import Data.Foldable import Data.Monoid+#if !(MIN_VERSION_base(4,8,0)) import Data.Traversable (Traversable(traverse))+#endif import Prelude hiding (null, length)+#if __GLASGOW_HASKELL__ >= 702+import GHC.Generics+#endif -- --------------------------------------------------------------------------- -- | A writer monad parameterized by the type @w@ of output to accumulate.@@ -116,6 +122,9 @@ -- The 'return' function produces the output 'mempty', while @>>=@ -- combines the outputs of the subcomputations using 'mappend'. newtype WriterT w m a = WriterT { runWriterT :: m (a, w) }+#if __GLASGOW_HASKELL__ >= 702+ deriving (Generic)+#endif instance (Eq w, Eq1 m) => Eq1 (WriterT w m) where liftEq eq (WriterT m1) (WriterT m2) = liftEq (liftEq2 eq (==)) m1 m2
Control/Monad/Trans/Writer/Strict.hs view
@@ -1,8 +1,9 @@ {-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Safe #-}+{-# LANGUAGE DeriveGeneric #-} #endif-#if __GLASGOW_HASKELL__ >= 710+#if __GLASGOW_HASKELL__ >= 710 && __GLASGOW_HASKELL__ < 802 {-# LANGUAGE AutoDeriveTypeable #-} #endif -----------------------------------------------------------------------------@@ -72,8 +73,13 @@ #endif import Data.Foldable import Data.Monoid+#if !(MIN_VERSION_base(4,8,0)) import Data.Traversable (Traversable(traverse))+#endif import Prelude hiding (null, length)+#if __GLASGOW_HASKELL__ >= 702+import GHC.Generics+#endif -- --------------------------------------------------------------------------- -- | A writer monad parameterized by the type @w@ of output to accumulate.@@ -119,6 +125,9 @@ -- The 'return' function produces the output 'mempty', while @>>=@ -- combines the outputs of the subcomputations using 'mappend'. newtype WriterT w m a = WriterT { runWriterT :: m (a, w) }+#if __GLASGOW_HASKELL__ >= 702+ deriving (Generic)+#endif instance (Eq w, Eq1 m) => Eq1 (WriterT w m) where liftEq eq (WriterT m1) (WriterT m2) = liftEq (liftEq2 eq (==)) m1 m2
Data/Functor/Constant.hs view
@@ -1,11 +1,15 @@ {-# LANGUAGE CPP #-}+#if __GLASGOW_HASKELL__ >= 608+{-# LANGUAGE DeriveDataTypeable #-}+#endif #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Safe #-}+{-# LANGUAGE DeriveGeneric #-} #endif #if __GLASGOW_HASKELL__ >= 706 {-# LANGUAGE PolyKinds #-} #endif-#if __GLASGOW_HASKELL__ >= 710+#if __GLASGOW_HASKELL__ >= 710 && __GLASGOW_HASKELL__ < 802 {-# LANGUAGE AutoDeriveTypeable #-} #endif -----------------------------------------------------------------------------@@ -32,23 +36,38 @@ import Control.Applicative import Data.Foldable+#if !(MIN_VERSION_base(4,8,0)) import Data.Monoid (Monoid(..)) import Data.Traversable (Traversable(traverse))+#endif #if MIN_VERSION_base(4,8,0) import Data.Bifunctor (Bifunctor(..)) #endif-#if MIN_VERSION_base(4,9,0)-import Data.Semigroup (Semigroup(..))+#if (MIN_VERSION_base(4,9,0)) && !(MIN_VERSION_base(4,11,0))+import Data.Semigroup (Semigroup((<>))) #endif #if MIN_VERSION_base(4,10,0) import Data.Bifoldable (Bifoldable(..)) import Data.Bitraversable (Bitraversable(..)) #endif import Prelude hiding (null, length)+#if __GLASGOW_HASKELL__ >= 702+import Data.Data+#endif+#if __GLASGOW_HASKELL__ >= 702+import GHC.Generics+#endif -- | Constant functor. newtype Constant a b = Constant { getConstant :: a }- deriving (Eq, Ord)+ deriving (Eq, Ord+#if __GLASGOW_HASKELL__ >= 608+ , Data+#endif+#if __GLASGOW_HASKELL__ >= 702+ , Generic, Generic1+#endif+ ) -- These instances would be equivalent to the derived instances of the -- newtype if the field were removed.
Data/Functor/Reverse.hs view
@@ -1,11 +1,12 @@ {-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Safe #-}+{-# LANGUAGE DeriveGeneric #-} #endif #if __GLASGOW_HASKELL__ >= 706 {-# LANGUAGE PolyKinds #-} #endif-#if __GLASGOW_HASKELL__ >= 710+#if __GLASGOW_HASKELL__ >= 710 && __GLASGOW_HASKELL__ < 802 {-# LANGUAGE AutoDeriveTypeable #-} #endif -----------------------------------------------------------------------------@@ -39,12 +40,20 @@ import qualified Control.Monad.Fail as Fail #endif import Data.Foldable-import Data.Traversable+#if !(MIN_VERSION_base(4,8,0))+import Data.Traversable (Traversable(traverse))+#endif import Data.Monoid+#if __GLASGOW_HASKELL__ >= 702+import GHC.Generics+#endif -- | The same functor, but with 'Foldable' and 'Traversable' instances -- that process the elements in the reverse order. newtype Reverse f a = Reverse { getReverse :: f a }+#if __GLASGOW_HASKELL__ >= 702+ deriving (Generic, Generic1)+#endif instance (Eq1 f) => Eq1 (Reverse f) where liftEq eq (Reverse x) (Reverse y) = liftEq eq x y
changelog view
@@ -1,5 +1,17 @@ -*-change-log-*- +0.6.0.0 Ross Paterson <R.Paterson@city.ac.uk> Jul 2021+ * Added quantified constraint to MonadTrans (for GHC >= 8.6)+ * Added Generic and Data instances+ * Added handleE, tryE and finallyE to Control.Monad.Trans.Except+ * Added hoistMaybe to Control.Monad.Trans.Maybe+ * Added Generic and Data instances+ * Added pass-throughs to instances for Backwards+ * Made Lift's <*> lazier+ * Remove long-deprecated selectToCont+ * Remove long-deprecated Control.Monad.Trans.Error+ * Remove long-deprecated Control.Monad.Trans.List+ 0.5.6.2 Ross Paterson <R.Paterson@city.ac.uk> Feb 2019 * Further backward compatability fix
transformers.cabal view
@@ -1,5 +1,5 @@ name: transformers-version: 0.5.6.2+version: 0.6.0.0 license: BSD3 license-file: LICENSE author: Andy Gill, Ross Paterson@@ -33,13 +33,14 @@ build-type: Simple extra-source-files: changelog-cabal-version: >= 1.6+cabal-version: >= 1.10 source-repository head type: darcs location: http://hub.darcs.net/ross/transformers library+ default-language: Haskell2010 build-depends: base >= 2 && < 6 hs-source-dirs: . if !impl(ghc>=7.9)@@ -70,9 +71,7 @@ Control.Monad.Trans.Class Control.Monad.Trans.Cont Control.Monad.Trans.Except- Control.Monad.Trans.Error Control.Monad.Trans.Identity- Control.Monad.Trans.List Control.Monad.Trans.Maybe Control.Monad.Trans.Reader Control.Monad.Trans.RWS