packages feed

either 3.2 → 3.3

raw patch · 3 files changed

+37/−13 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Control.Monad.Trans.Either: instance (Functor m, Monad m) => Alt (EitherT e m)
- Control.Monad.Trans.Either: instance (Functor m, Monad m) => Applicative (EitherT e m)
- Control.Monad.Trans.Either: instance (Functor m, Monad m) => Apply (EitherT e m)
- Control.Monad.Trans.Either: instance (Functor m, Monad m) => Bind (EitherT e m)
- Control.Monad.Trans.Either: instance (Monad m, Semigroup e) => Semigroup (EitherT e m a)
- Control.Monad.Trans.Either: instance Functor m => Functor (EitherT e m)
- Control.Monad.Trans.Either: instance Traversable f => Traversable (EitherT e f)
+ Control.Monad.Trans.Either: instance (Monad f, Traversable f) => Traversable (EitherT e f)
+ Control.Monad.Trans.Either: instance (Monad m, Monoid e) => Alternative (EitherT e m)
+ Control.Monad.Trans.Either: instance (Monad m, Monoid e) => MonadPlus (EitherT e m)
+ Control.Monad.Trans.Either: instance (Monad m, Semigroup e) => Alt (EitherT e m)
+ Control.Monad.Trans.Either: instance Monad m => Applicative (EitherT e m)
+ Control.Monad.Trans.Either: instance Monad m => Apply (EitherT e m)
+ Control.Monad.Trans.Either: instance Monad m => Bind (EitherT e m)
+ Control.Monad.Trans.Either: instance Monad m => Functor (EitherT e m)
+ Control.Monad.Trans.Either: instance Monad m => Semigroup (EitherT e m a)

Files

CHANGELOG.markdown view
@@ -1,3 +1,9 @@+3.3+---+* Inverted roles between `Semigroup` and `Alt`. This let us write `Alternative` and `MonadPlus` instances that are compatible.+* Removed the `Functor` constraint on most instances in exchange for incurring a `Monad` constraint on `Traversable`. `EitherT`+  is after all, a `Monad` transformer first and foremost.+ 3.2 --- * Changed the `Semigroup` to use a `Semigroup` to combine `Left` branches. Left `Alt` untouched, so you can mix and match.
either.cabal view
@@ -1,6 +1,6 @@ name:          either category:      Control, Monads-version:       3.2+version:       3.3 license:       BSD3 cabal-version: >= 1.6 license-file:  LICENSE
src/Control/Monad/Trans/Either.hs view
@@ -26,7 +26,7 @@   ) where  import Control.Applicative-import Control.Monad (liftM)+import Control.Monad (liftM, MonadPlus(..)) import Control.Monad.Cont.Class import Control.Monad.Error.Class import Control.Monad.Fix@@ -117,11 +117,11 @@ hoistEither = EitherT . return {-# INLINE hoistEither #-} -instance Functor m => Functor (EitherT e m) where-  fmap f = EitherT . fmap (fmap f) . runEitherT+instance Monad m => Functor (EitherT e m) where+  fmap f = EitherT . liftM (fmap f) . runEitherT   {-# INLINE fmap #-} -instance (Functor m, Monad m) => Apply (EitherT e m) where+instance Monad m => Apply (EitherT e m) where   EitherT f <.> EitherT v = EitherT $ f >>= \mf -> case mf of     Left  e -> return (Left e)     Right k -> v >>= \mv -> case mv of@@ -129,7 +129,7 @@       Right x -> return (Right (k x))   {-# INLINE (<.>) #-} -instance (Functor m, Monad m) => Applicative (EitherT e m) where+instance Monad m => Applicative (EitherT e m) where   pure a  = EitherT $ return (Right a)   {-# INLINE pure #-}   EitherT f <*> EitherT v = EitherT $ f >>= \mf -> case mf of@@ -139,21 +139,39 @@       Right x -> return (Right (k x))   {-# INLINE (<*>) #-} -instance (Monad m, Semigroup e) => Semigroup (EitherT e m a) where-  EitherT m <> EitherT n = EitherT $ m >>= \a -> case a of+instance (Monad m, Monoid e) => Alternative (EitherT e m) where+  EitherT m <|> EitherT n = EitherT $ m >>= \a -> case a of     Left l -> liftM (\b -> case b of-      Left l' -> Left (l <> l')+      Left l' -> Left (mappend l l')       Right r -> Right r) n     Right r -> return (Right r)+  {-# INLINE (<|>) #-}++  empty = EitherT $ return (Left mempty)+  {-# INLINE empty #-}++instance (Monad m, Monoid e) => MonadPlus (EitherT e m) where+  mplus = (<|>)+  {-# INLINE mplus #-}++  mzero = empty+  {-# INLINE mzero #-}++instance Monad m => Semigroup (EitherT e m a) where+  EitherT m <> EitherT n = EitherT $ m >>= \a -> case a of+    Left _  -> n+    Right r -> return (Right r)   {-# INLINE (<>) #-} -instance (Functor m, Monad m) => Alt (EitherT e m) where+instance (Monad m, Semigroup e) => Alt (EitherT e m) where   EitherT m <!> EitherT n = EitherT $ m >>= \a -> case a of-    Left _  -> n+    Left l -> liftM (\b -> case b of+      Left l' -> Left (l <> l')+      Right r -> Right r) n     Right r -> return (Right r)   {-# INLINE (<!>) #-} -instance (Functor m, Monad m) => Bind (EitherT e m) where+instance Monad m => Bind (EitherT e m) where   (>>-) = (>>=)   {-# INLINE (>>-) #-} @@ -235,7 +253,7 @@   foldMap f = foldMap (either mempty f) . runEitherT   {-# INLINE foldMap #-} -instance Traversable f => Traversable (EitherT e f) where+instance (Monad f, Traversable f) => Traversable (EitherT e f) where   traverse f (EitherT a) =     EitherT <$> traverse (either (pure . Left) (fmap Right . f)) a   {-# INLINE traverse #-}