diff --git a/Control/Applicative/Backwards.hs b/Control/Applicative/Backwards.hs index be1b29c..4270aa4 100644 --- a/Control/Applicative/Backwards.hs +++ b/Control/Applicative/Backwards.hs @@ -143,3 +143,17 @@ instance (Contravariant f) => Contravariant (Backwards f) where contramap f = Backwards . contramap f . forwards {-# INLINE contramap #-} #endif + +#if MIN_VERSION_base(4,9,0) +instance (Semigroup a, Applicative f) => Semigroup (Backwards f a) where + ma <> mb = (<>) <$> ma <*> mb + {-# INLINE (<>) #-} +#endif + +instance (Monoid a, Applicative f) => Monoid (Backwards f a) where + mempty = pure mempty + {-# INLINE mempty #-} +#if !MIN_VERSION_base(4,11,0) + ma `mappend` mb = (<>) <$> ma <*> mb + {-# INLINE mappend #-} +#endif diff --git a/Control/Applicative/Lift.hs b/Control/Applicative/Lift.hs index df556cf..1ffe35b 100644 --- a/Control/Applicative/Lift.hs +++ b/Control/Applicative/Lift.hs @@ -128,6 +128,20 @@ instance (Foldable1 f) => Foldable1 (Lift f) where {-# INLINE foldMap1 #-} #endif +#if MIN_VERSION_base(4,9,0) +instance (Semigroup a, Applicative f) => Semigroup (Lift f a) where + ma <> mb = (<>) <$> ma <*> mb + {-# INLINE (<>) #-} +#endif + +instance (Monoid a, Applicative f) => Monoid (Lift f a) where + mempty = pure mempty + {-# INLINE mempty #-} +#if !MIN_VERSION_base(4,11,0) + ma `mappend` mb = (<>) <$> ma <*> mb + {-# INLINE mappend #-} +#endif + -- | Projection to the other functor. unLift :: (Applicative f) => Lift f a -> f a unLift (Pure x) = pure x diff --git a/Control/Monad/Trans/Accum.hs b/Control/Monad/Trans/Accum.hs index cb06eba..a9d8f9d 100644 --- a/Control/Monad/Trans/Accum.hs +++ b/Control/Monad/Trans/Accum.hs @@ -247,6 +247,20 @@ instance (Monoid w, Functor m, MonadIO m) => MonadIO (AccumT w m) where liftIO = lift . liftIO {-# INLINE liftIO #-} +#if MIN_VERSION_base(4,9,0) +instance (Semigroup a, Monoid w, Monad m) => Semigroup (AccumT w m a) where + ma <> mb = (<>) <$> ma <*> mb + {-# INLINE (<>) #-} +#endif + +instance (Monoid a, Monoid w, Monad m) => Monoid (AccumT w m a) where + mempty = pure mempty + {-# INLINE mempty #-} +#if !MIN_VERSION_base(4,11,0) + ma `mappend` mb = (<>) <$> ma <*> mb + {-# INLINE mappend #-} +#endif + -- | @'look'@ is an action that fetches all the previously accumulated output. look :: (Monoid w, Monad m) => AccumT w m w look = AccumT $ \ w -> return (w, mempty) diff --git a/Control/Monad/Trans/Cont.hs b/Control/Monad/Trans/Cont.hs index d51a68e..e66caaf 100644 --- a/Control/Monad/Trans/Cont.hs +++ b/Control/Monad/Trans/Cont.hs @@ -206,6 +206,20 @@ instance (MonadIO m) => MonadIO (ContT r m) where liftIO = lift . liftIO {-# INLINE liftIO #-} +#if MIN_VERSION_base(4,9,0) +instance Semigroup a => Semigroup (ContT r m a) where + ma <> mb = (<>) <$> ma <*> mb + {-# INLINE (<>) #-} +#endif + +instance Monoid a => Monoid (ContT r m a) where + mempty = pure mempty + {-# INLINE mempty #-} +#if !MIN_VERSION_base(4,11,0) + ma `mappend` mb = (<>) <$> ma <*> mb + {-# INLINE mappend #-} +#endif + -- | @callCC@ (call-with-current-continuation) calls its argument -- function, passing it the current continuation. It provides -- an escape continuation mechanism for use with continuation diff --git a/Control/Monad/Trans/Except.hs b/Control/Monad/Trans/Except.hs index 049a0f3..e8206fe 100644 --- a/Control/Monad/Trans/Except.hs +++ b/Control/Monad/Trans/Except.hs @@ -281,6 +281,20 @@ instance Contravariant m => Contravariant (ExceptT e m) where {-# INLINE contramap #-} #endif +#if MIN_VERSION_base(4,9,0) +instance (Semigroup a, Monad m) => Semigroup (ExceptT e m a) where + ma <> mb = (<>) <$> ma <*> mb + {-# INLINE (<>) #-} +#endif + +instance (Monoid a, Monad m) => Monoid (ExceptT e m a) where + mempty = pure mempty + {-# INLINE mempty #-} +#if !MIN_VERSION_base(4,11,0) + ma `mappend` mb = (<>) <$> ma <*> mb + {-# INLINE mappend #-} +#endif + -- | Signal an exception value @e@. -- -- * @'runExceptT' ('throwE' e) = 'return' ('Left' e)@ diff --git a/Control/Monad/Trans/Identity.hs b/Control/Monad/Trans/Identity.hs index f150ed7..b2a90d0 100644 --- a/Control/Monad/Trans/Identity.hs +++ b/Control/Monad/Trans/Identity.hs @@ -185,6 +185,20 @@ instance (Contravariant f) => Contravariant (IdentityT f) where {-# INLINE contramap #-} #endif +#if MIN_VERSION_base(4,9,0) +instance (Semigroup a, Applicative m) => Semigroup (IdentityT m a) where + ma <> mb = (<>) <$> ma <*> mb + {-# INLINE (<>) #-} +#endif + +instance (Monoid a, Applicative m) => Monoid (IdentityT m a) where + mempty = pure mempty + {-# INLINE mempty #-} +#if !MIN_VERSION_base(4,11,0) + ma `mappend` mb = (<>) <$> ma <*> mb + {-# INLINE mappend #-} +#endif + -- | Lift a unary operation to the new monad. mapIdentityT :: (m a -> n b) -> IdentityT m a -> IdentityT n b mapIdentityT f = IdentityT . f . runIdentityT diff --git a/Control/Monad/Trans/Maybe.hs b/Control/Monad/Trans/Maybe.hs index cab161d..ccad235 100644 --- a/Control/Monad/Trans/Maybe.hs +++ b/Control/Monad/Trans/Maybe.hs @@ -229,6 +229,20 @@ instance Contravariant m => Contravariant (MaybeT m) where {-# INLINE contramap #-} #endif +#if MIN_VERSION_base(4,9,0) +instance (Semigroup a, Monad m) => Semigroup (MaybeT m a) where + ma <> mb = (<>) <$> ma <*> mb + {-# INLINE (<>) #-} +#endif + +instance (Monoid a, Monad m) => Monoid (MaybeT m a) where + mempty = pure mempty + {-# INLINE mempty #-} +#if !MIN_VERSION_base(4,11,0) + ma `mappend` mb = (<>) <$> ma <*> mb + {-# INLINE mappend #-} +#endif + -- | Lift a @callCC@ operation to the new monad. liftCallCC :: CallCC m (Maybe a) (Maybe b) -> CallCC (MaybeT m) a b liftCallCC callCC f = diff --git a/Control/Monad/Trans/RWS/CPS.hs b/Control/Monad/Trans/RWS/CPS.hs index f089db6..fd9f7d9 100644 --- a/Control/Monad/Trans/RWS/CPS.hs +++ b/Control/Monad/Trans/RWS/CPS.hs @@ -272,6 +272,21 @@ instance MonadTrans (RWST r w s) where instance (MonadIO m) => MonadIO (RWST r w s m) where liftIO = lift . liftIO {-# INLINE liftIO #-} + +#if MIN_VERSION_base(4,9,0) +instance (Semigroup a, Monad m) => Semigroup (RWST r w s m a) where + ma <> mb = (<>) <$> ma <*> mb + {-# INLINE (<>) #-} +#endif + +instance (Monoid a, Monad m) => Monoid (RWST r w s m a) where + mempty = pure mempty + {-# INLINE mempty #-} +#if !MIN_VERSION_base(4,11,0) + ma `mappend` mb = (<>) <$> ma <*> mb + {-# INLINE mappend #-} +#endif + -- --------------------------------------------------------------------------- -- Reader operations diff --git a/Control/Monad/Trans/RWS/Lazy.hs b/Control/Monad/Trans/RWS/Lazy.hs index 5fd8f2d..0d7a5cd 100644 --- a/Control/Monad/Trans/RWS/Lazy.hs +++ b/Control/Monad/Trans/RWS/Lazy.hs @@ -253,6 +253,20 @@ instance Contravariant m => Contravariant (RWST r w s m) where {-# INLINE contramap #-} #endif +#if MIN_VERSION_base(4,9,0) +instance (Semigroup a, Monoid w, Monad m) => Semigroup (RWST r w s m a) where + ma <> mb = (<>) <$> ma <*> mb + {-# INLINE (<>) #-} +#endif + +instance (Monoid a, Monoid w, Monad m) => Monoid (RWST r w s m a) where + mempty = pure mempty + {-# INLINE mempty #-} +#if !MIN_VERSION_base(4,11,0) + ma `mappend` mb = (<>) <$> ma <*> mb + {-# INLINE mappend #-} +#endif + -- --------------------------------------------------------------------------- -- Reader operations diff --git a/Control/Monad/Trans/RWS/Strict.hs b/Control/Monad/Trans/RWS/Strict.hs index a7f66db..d5165b4 100644 --- a/Control/Monad/Trans/RWS/Strict.hs +++ b/Control/Monad/Trans/RWS/Strict.hs @@ -257,6 +257,16 @@ instance Contravariant m => Contravariant (RWST r w s m) where {-# INLINE contramap #-} #endif +#if MIN_VERSION_base(4,9,0) +instance (Semigroup a, Monoid w, Monad m) => Semigroup (RWST r w s m a) where + ma <> mb = (<>) <$> ma <*> mb + {-# INLINE (<>) #-} + +instance (Monoid a, Monoid w, Monad m) => Monoid (RWST r w s m a) where + mempty = pure mempty + {-# INLINE mempty #-} +#endif + -- --------------------------------------------------------------------------- -- Reader operations diff --git a/Control/Monad/Trans/Reader.hs b/Control/Monad/Trans/Reader.hs index dbcf4c9..b61c35f 100644 --- a/Control/Monad/Trans/Reader.hs +++ b/Control/Monad/Trans/Reader.hs @@ -236,6 +236,20 @@ instance Contravariant m => Contravariant (ReaderT r m) where {-# INLINE contramap #-} #endif +#if MIN_VERSION_base(4,9,0) +instance (Semigroup a, Applicative m) => Semigroup (ReaderT r m a) where + ma <> mb = (<>) <$> ma <*> mb + {-# INLINE (<>) #-} +#endif + +instance (Monoid a, Applicative m) => Monoid (ReaderT r m a) where + mempty = pure mempty + {-# INLINE mempty #-} +#if !MIN_VERSION_base(4,11,0) + ma `mappend` mb = (<>) <$> ma <*> mb + {-# INLINE mappend #-} +#endif + liftReaderT :: m a -> ReaderT r m a liftReaderT m = ReaderT (const m) {-# INLINE liftReaderT #-} diff --git a/Control/Monad/Trans/Select.hs b/Control/Monad/Trans/Select.hs index 29eb6c4..b812e49 100644 --- a/Control/Monad/Trans/Select.hs +++ b/Control/Monad/Trans/Select.hs @@ -154,6 +154,20 @@ instance (MonadIO m) => MonadIO (SelectT r m) where liftIO = lift . liftIO {-# INLINE liftIO #-} +#if MIN_VERSION_base(4,9,0) +instance (Semigroup a, Monad m) => Semigroup (SelectT r m a) where + ma <> mb = (<>) <$> ma <*> mb + {-# INLINE (<>) #-} +#endif + +instance (Monoid a, Monad m) => Monoid (SelectT r m a) where + mempty = pure mempty + {-# INLINE mempty #-} +#if !MIN_VERSION_base(4,11,0) + ma `mappend` mb = (<>) <$> ma <*> mb + {-# INLINE mappend #-} +#endif + -- | 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 diff --git a/Control/Monad/Trans/State/Lazy.hs b/Control/Monad/Trans/State/Lazy.hs index 67fd597..dd4bcaa 100644 --- a/Control/Monad/Trans/State/Lazy.hs +++ b/Control/Monad/Trans/State/Lazy.hs @@ -277,6 +277,20 @@ instance Contravariant m => Contravariant (StateT s m) where {-# INLINE contramap #-} #endif +#if MIN_VERSION_base(4,9,0) +instance (Semigroup a, Monad m) => Semigroup (StateT s m a) where + ma <> mb = (<>) <$> ma <*> mb + {-# INLINE (<>) #-} +#endif + +instance (Monoid a, Monad m) => Monoid (StateT s m a) where + mempty = pure mempty + {-# INLINE mempty #-} +#if !MIN_VERSION_base(4,11,0) + ma `mappend` mb = (<>) <$> ma <*> mb + {-# INLINE mappend #-} +#endif + -- | Fetch the current value of the state within the monad. get :: (Monad m) => StateT s m s get = state $ \ s -> (s, s) diff --git a/Control/Monad/Trans/State/Strict.hs b/Control/Monad/Trans/State/Strict.hs index 040c871..4e4cc82 100644 --- a/Control/Monad/Trans/State/Strict.hs +++ b/Control/Monad/Trans/State/Strict.hs @@ -270,6 +270,16 @@ instance Contravariant m => Contravariant (StateT s m) where {-# INLINE contramap #-} #endif +#if MIN_VERSION_base(4,9,0) +instance (Semigroup a, Monad m) => Semigroup (StateT s m a) where + ma <> mb = (<>) <$> ma <*> mb + {-# INLINE (<>) #-} + +instance (Monoid a, Monad m) => Monoid (StateT s m a) where + mempty = pure mempty + {-# INLINE mempty #-} +#endif + -- | Fetch the current value of the state within the monad. get :: (Monad m) => StateT s m s get = state $ \ s -> (s, s) diff --git a/Control/Monad/Trans/Writer/CPS.hs b/Control/Monad/Trans/Writer/CPS.hs index 3b63c49..32fa561 100644 --- a/Control/Monad/Trans/Writer/CPS.hs +++ b/Control/Monad/Trans/Writer/CPS.hs @@ -228,6 +228,20 @@ instance (MonadIO m) => MonadIO (WriterT w m) where liftIO = lift . liftIO {-# INLINE liftIO #-} +#if MIN_VERSION_base(4,9,0) +instance (Semigroup a, Monad m) => Semigroup (WriterT w m a) where + ma <> mb = (<>) <$> ma <*> mb + {-# INLINE (<>) #-} +#endif + +instance (Monoid a, Monad m) => Monoid (WriterT w m a) where + mempty = pure mempty + {-# INLINE mempty #-} +#if !MIN_VERSION_base(4,11,0) + ma `mappend` mb = (<>) <$> ma <*> mb + {-# INLINE mappend #-} +#endif + -- | @'tell' w@ is an action that produces the output @w@. tell :: (Monoid w, Monad m) => w -> WriterT w m () tell w = writer ((), w) diff --git a/Control/Monad/Trans/Writer/Lazy.hs b/Control/Monad/Trans/Writer/Lazy.hs index 8da513b..cd264e6 100644 --- a/Control/Monad/Trans/Writer/Lazy.hs +++ b/Control/Monad/Trans/Writer/Lazy.hs @@ -265,6 +265,20 @@ instance Contravariant m => Contravariant (WriterT w m) where {-# INLINE contramap #-} #endif +#if MIN_VERSION_base(4,9,0) +instance (Semigroup a, Monoid w, Applicative m) => Semigroup (WriterT w m a) where + ma <> mb = (<>) <$> ma <*> mb + {-# INLINE (<>) #-} +#endif + +instance (Monoid a, Monoid w, Applicative m) => Monoid (WriterT w m a) where + mempty = pure mempty + {-# INLINE mempty #-} +#if !MIN_VERSION_base(4,11,0) + ma `mappend` mb = (<>) <$> ma <*> mb + {-# INLINE mappend #-} +#endif + -- | @'tell' w@ is an action that produces the output @w@. tell :: (Monad m) => w -> WriterT w m () tell w = writer ((), w) diff --git a/Control/Monad/Trans/Writer/Strict.hs b/Control/Monad/Trans/Writer/Strict.hs index d585da9..6453d76 100644 --- a/Control/Monad/Trans/Writer/Strict.hs +++ b/Control/Monad/Trans/Writer/Strict.hs @@ -268,6 +268,20 @@ instance Contravariant m => Contravariant (WriterT w m) where {-# INLINE contramap #-} #endif +#if MIN_VERSION_base(4,9,0) +instance (Semigroup a, Monoid w, Applicative m) => Semigroup (WriterT w m a) where + ma <> mb = (<>) <$> ma <*> mb + {-# INLINE (<>) #-} +#endif + +instance (Monoid a, Monoid w, Applicative m) => Monoid (WriterT w m a) where + mempty = pure mempty + {-# INLINE mempty #-} +#if !MIN_VERSION_base(4,11,0) + ma `mappend` mb = (<>) <$> ma <*> mb + {-# INLINE mappend #-} +#endif + -- | @'tell' w@ is an action that produces the output @w@. tell :: (Monad m) => w -> WriterT w m () tell w = writer ((), w)