1
1
-- | This module defines the _exception monad transformer_ `ExceptT`.
2
2
3
- module Control.Monad.Except.Trans
3
+ module Control.Monad.Except.Trans
4
4
( ExceptT (..), runExceptT , withExceptT , mapExceptT
5
5
, module Control.Monad.Trans
6
6
, module Control.Monad.Error.Class
7
7
) where
8
8
9
- import Prelude
9
+ import Prelude
10
10
11
11
import Data.Tuple (Tuple (..))
12
12
import Data.Either (Either (..), either )
@@ -18,9 +18,6 @@ import Control.Monad.Rec.Class (MonadRec, tailRecM)
18
18
import Control.Monad.Eff.Class (MonadEff , liftEff )
19
19
import Control.Monad.Error.Class (MonadError , throwError , catchError )
20
20
import Control.Monad.Cont.Class (MonadCont , callCC )
21
- import Control.Monad.Reader.Class
22
- import Control.Monad.State.Class
23
- import Control.Monad.Writer.Class
24
21
import Control.Monad.RWS.Class
25
22
import Control.Monad.Trans
26
23
import Control.MonadPlus (MonadPlus )
@@ -99,29 +96,29 @@ instance monadTransExceptT :: MonadTrans (ExceptT e) where
99
96
instance monadEffExceptT :: (MonadEff eff m ) => MonadEff eff (ExceptT e m ) where
100
97
liftEff = lift <<< liftEff
101
98
102
- instance monadContExceptT :: (MonadCont m ) => MonadCont (ExceptT e m ) where
99
+ instance monadContExceptT :: (MonadCont m ) => MonadCont (ExceptT e m ) where
103
100
callCC f = ExceptT $ callCC $ \c -> runExceptT (f (\a -> ExceptT $ c (Right a)))
104
101
105
102
instance monadErrorExceptT :: (Monad m ) => MonadError e (ExceptT e m ) where
106
103
throwError = ExceptT <<< pure <<< Left
107
104
catchError m handler = ExceptT (runExceptT m >>= either (runExceptT <<< handler) (pure <<< Right ))
108
105
109
106
instance monadReaderExceptT :: (MonadReader r m ) => MonadReader r (ExceptT e m ) where
110
- ask = lift ask
107
+ ask = lift ask
111
108
local f = mapExceptT (local f)
112
109
113
110
instance monadStateExceptT :: (MonadState s m ) => MonadState s (ExceptT e m ) where
114
111
state f = lift (state f)
115
112
116
- instance monadWriterExceptT :: (MonadWriter w m ) => MonadWriter w (ExceptT e m ) where
117
- writer wd = lift (writer wd)
118
- listen = mapExceptT $ \m -> do
119
- Tuple a w <- listen m
113
+ instance monadWriterExceptT :: (MonadWriter w m ) => MonadWriter w (ExceptT e m ) where
114
+ writer wd = lift (writer wd)
115
+ listen = mapExceptT $ \m -> do
116
+ Tuple a w <- listen m
120
117
return $ (\r -> Tuple r w) <$> a
121
- pass = mapExceptT $ \m -> pass $ do
122
- a <- m
123
- return $ case a of
124
- Left e -> Tuple (Left e) id
125
- Right (Tuple r f) -> Tuple (Right r) f
118
+ pass = mapExceptT $ \m -> pass $ do
119
+ a <- m
120
+ return $ case a of
121
+ Left e -> Tuple (Left e) id
122
+ Right (Tuple r f) -> Tuple (Right r) f
126
123
127
124
instance monadRWSExceptT :: (Monoid w , MonadRWS r w s m ) => MonadRWS r w s (ExceptT e m )
0 commit comments