Skip to content

Commit 1477220

Browse files
committed
Merge pull request #69 from libscott/master
generalise Control.Monad.Except.except to ExceptT
2 parents 241e114 + 92c2f39 commit 1477220

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/Control/Monad/Except.purs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11

22
module Control.Monad.Except
33
( Except()
4-
, except
54
, runExcept
65
, mapExcept
76
, withExcept
87
, module Control.Monad.Error.Class
8+
, module Trans
99
) where
1010

1111
import Prelude
1212

1313
import Control.Monad.Error.Class
1414
import Control.Monad.Except.Trans (ExceptT(..), withExceptT, runExceptT, mapExceptT)
15+
import qualified Control.Monad.Except.Trans (except) as Trans
1516

1617
import Data.Either (Either())
1718
import Data.Identity (Identity(..), runIdentity)
@@ -33,10 +34,6 @@ import Data.Identity (Identity(..), runIdentity)
3334
-- | instance for the exception type.
3435
type Except e a = ExceptT e Identity a
3536

36-
-- | Construct a computation in the `Except` monad from an `Either` value.
37-
except :: forall e a. Either e a -> Except e a
38-
except = ExceptT <<< Identity
39-
4037
-- | Run a computation in the `Except` monad. The inverse of `except`.
4138
runExcept :: forall e a. Except e a -> Either e a
4239
runExcept = runIdentity <<< runExceptT

src/Control/Monad/Except/Trans.purs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- | This module defines the _exception monad transformer_ `ExceptT`.
22

33
module Control.Monad.Except.Trans
4-
( ExceptT(..), runExceptT, withExceptT, mapExceptT
4+
( ExceptT(..), runExceptT, withExceptT, mapExceptT, except
55
, module Control.Monad.Trans
66
, module Control.Monad.Error.Class
77
) where
@@ -47,6 +47,10 @@ withExceptT f = ExceptT <<< (<$>) (mapLeft f) <<< runExceptT
4747
mapExceptT :: forall e e' m n a b. (m (Either e a) -> n (Either e' b)) -> ExceptT e m a -> ExceptT e' n b
4848
mapExceptT f m = ExceptT (f (runExceptT m))
4949

50+
-- | Construct a computation in the `ExceptT` transformer from an `Either` value.
51+
except :: forall e m a. (Applicative m) => Either e a -> ExceptT e m a
52+
except = ExceptT <<< return
53+
5054
instance functorExceptT :: (Functor m) => Functor (ExceptT e m) where
5155
map f = mapExceptT ((<$>) ((<$>) f))
5256

0 commit comments

Comments
 (0)