packages feed

EitherT 0.0.1 → 0.1.0

raw patch · 3 files changed

+55/−63 lines, 3 filesdep ~basedep ~mtlPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base, mtl

API changes (from Hackage documentation)

- Control.Monad.Either: EitherT :: m (Either l a) -> EitherT l m a
- Control.Monad.Either: instance (Applicative f) => Applicative (EitherT l f)
- Control.Monad.Either: instance (Functor f) => Functor (EitherT l f)
- Control.Monad.Either: instance (Monad m) => Monad (EitherT l m)
- Control.Monad.Either: instance (MonadIO m) => MonadIO (EitherT l m)
- Control.Monad.Either: instance Applicative (Either l)
- Control.Monad.Either: instance Monad (Either l)
- Control.Monad.Either: instance MonadTrans (EitherT l)
- Control.Monad.Either: left :: (Monad m) => l -> EitherT l m a
- Control.Monad.Either: newtype EitherT l m a
- Control.Monad.Either: runEitherT :: EitherT l m a -> m (Either l a)
+ Control.Monad.Trans.Either: EitherT :: m (Either l a) -> EitherT l m a
+ Control.Monad.Trans.Either: instance (Applicative m, Monoid a) => Monoid (EitherT l m a)
+ Control.Monad.Trans.Either: instance Applicative f => Applicative (EitherT l f)
+ Control.Monad.Trans.Either: instance Functor f => Functor (EitherT l f)
+ Control.Monad.Trans.Either: instance Monad m => Monad (EitherT l m)
+ Control.Monad.Trans.Either: instance MonadIO m => MonadIO (EitherT l m)
+ Control.Monad.Trans.Either: instance MonadTrans (EitherT l)
+ Control.Monad.Trans.Either: left :: Monad m => l -> EitherT l m a
+ Control.Monad.Trans.Either: newtype EitherT l m a
+ Control.Monad.Trans.Either: runEitherT :: EitherT l m a -> m (Either l a)

Files

EitherT.cabal view
@@ -1,5 +1,5 @@ Name:                EitherT-Version:             0.0.1+Version:             0.1.0 Synopsis:            EitherT monad transformer Description:         Support for computations with informative failures. License:             BSD3@@ -10,6 +10,6 @@ Stability:           experimental Build-Type:          Simple HS-Source-Dirs:      src-Build-Depends:       base >= 4 && < 5, mtl-Exposed-modules:     Control.Monad.Either-ghc-options:         -Wall +Build-Depends:       base >= 4 && < 5, mtl >= 2.0 && < 2.1+Exposed-modules:     Control.Monad.Trans.Either+ghc-options:         -Wall
− src/Control/Monad/Either.hs
@@ -1,59 +0,0 @@-{-# OPTIONS -Wall -O2 -fno-warn-orphans #-}-{-# LANGUAGE ScopedTypeVariables #-}---- Exports Applicative/Monad instances for Either-module Control.Monad.Either(EitherT(..), left) where--import Control.Monad(liftM)-import Control.Monad.Trans(MonadTrans(..))-import Control.Monad.Instances()-import Control.Monad.Trans(MonadIO(..))-import Control.Applicative(Applicative(..), liftA2)--newtype EitherT l m a = EitherT { runEitherT :: m (Either l a) }-inEitherT0 :: m (Either l a) -> EitherT l m a-inEitherT0 = EitherT-inEitherT1 :: (m (Either l a) -> m (Either l b)) ->-              EitherT l m a -> EitherT l m b-inEitherT1 f = inEitherT0 . f . runEitherT-inEitherT2 :: (m (Either l a) -> m (Either l b) -> m (Either l c)) ->-              EitherT l m a -> EitherT l m b -> EitherT l m c-inEitherT2 f = inEitherT1 . f . runEitherT--left :: Monad m => l -> EitherT l m a-left = EitherT . return . Left--instance Monad m => Monad (EitherT l m) where-  -- We can't support "fail" because we don't have a-  -- (String -> l). But we can at least make it a Left, with the error inside-  -- it as a pure exception.-  fail = EitherT . return . Left . error-  return = EitherT . return . Right-  EitherT x >>= f = EitherT $ do-    res <- x-    case res of-      Right r -> runEitherT . f $ r-      Left l -> return (Left l)--instance MonadTrans (EitherT l) where-  lift = EitherT . liftM Right--instance Applicative (Either l) where-  pure = Right-  Right f <*> Right x = Right (f x)-  Left e <*> _ = Left e-  _ <*> Left e = Left e--instance Monad (Either l) where-  return = pure-  Right x >>= f = f x-  Left e >>= _ = Left e--instance Functor f => Functor (EitherT l f) where-  fmap = inEitherT1 . fmap . fmap-instance Applicative f => Applicative (EitherT l f) where-  pure = inEitherT0 . pure . pure-  (<*>) = inEitherT2 . liftA2 . liftA2 $ id--instance (MonadIO m) => MonadIO (EitherT l m) where-  liftIO = lift . liftIO
+ src/Control/Monad/Trans/Either.hs view
@@ -0,0 +1,51 @@+{-# OPTIONS -Wall -O2 -fno-warn-orphans #-}++module Control.Monad.Trans.Either(EitherT(..), left) where++import Data.Monoid(Monoid(..))+import Control.Monad(liftM)+import Control.Monad.Trans(MonadTrans(..))+import Control.Monad.Instances()+import Control.Monad.Trans(MonadIO(..))+import Control.Applicative(Applicative(..), liftA2)++newtype EitherT l m a = EitherT { runEitherT :: m (Either l a) }+inEitherT0 :: m (Either l a) -> EitherT l m a+inEitherT0 = EitherT+inEitherT1 :: (m (Either l a) -> m (Either l b)) ->+              EitherT l m a -> EitherT l m b+inEitherT1 f = inEitherT0 . f . runEitherT+inEitherT2 :: (m (Either l a) -> m (Either l b) -> m (Either l c)) ->+              EitherT l m a -> EitherT l m b -> EitherT l m c+inEitherT2 f = inEitherT1 . f . runEitherT++left :: Monad m => l -> EitherT l m a+left = EitherT . return . Left++instance Monad m => Monad (EitherT l m) where+  -- We can't support "fail" because we don't have a+  -- (String -> l). But we can at least make it a Left, with the error inside+  -- it as a pure exception.+  fail = EitherT . return . Left . error+  return = EitherT . return . Right+  EitherT x >>= f = EitherT $ do+    res <- x+    case res of+      Right r -> runEitherT . f $ r+      Left l -> return (Left l)++instance MonadTrans (EitherT l) where+  lift = EitherT . liftM Right++instance Functor f => Functor (EitherT l f) where+  fmap = inEitherT1 . fmap . fmap+instance Applicative f => Applicative (EitherT l f) where+  pure = inEitherT0 . pure . pure+  (<*>) = inEitherT2 . liftA2 . liftA2 $ id++instance (MonadIO m) => MonadIO (EitherT l m) where+  liftIO = lift . liftIO++instance (Applicative m, Monoid a) => Monoid (EitherT l m a) where+  mempty = pure mempty+  mappend = liftA2 mappend