2
2
3
3
module Control.Monad.Except.Trans
4
4
( ExceptT (..), runExceptT , withExceptT , mapExceptT , except
5
- , module Control.Monad.Trans
5
+ , module Control.Monad.Trans.Class
6
6
, module Control.Monad.Error.Class
7
7
) where
8
8
@@ -13,18 +13,18 @@ import Control.Alternative (class Alternative)
13
13
import Control.Monad.Cont.Class (class MonadCont , callCC )
14
14
import Control.Monad.Eff.Class (class MonadEff , liftEff )
15
15
import Control.Monad.Error.Class (class MonadError , throwError , catchError )
16
- import Control.Monad.Reader.Class (class MonadReader , local , ask )
16
+ import Control.Monad.Reader.Class (class MonadAsk , class MonadReader , ask , local )
17
17
import Control.Monad.Rec.Class (class MonadRec , tailRecM , Step (..))
18
- import Control.Monad.RWS.Class (class MonadRWS )
19
18
import Control.Monad.State.Class (class MonadState , state )
20
- import Control.Monad.Trans (class MonadTrans , lift )
21
- import Control.Monad.Writer.Class (class MonadWriter , pass , listen , writer )
19
+ import Control.Monad.Trans.Class (class MonadTrans , lift )
20
+ import Control.Monad.Writer.Class (class MonadWriter , class MonadTell , pass , listen , tell )
22
21
import Control.MonadPlus (class MonadPlus )
23
22
import Control.MonadZero (class MonadZero )
24
23
import Control.Plus (class Plus )
25
24
26
25
import Data.Either (Either (..), either )
27
26
import Data.Monoid (class Monoid , mempty )
27
+ import Data.Newtype (class Newtype )
28
28
import Data.Tuple (Tuple (..))
29
29
30
30
-- | A monad transformer which adds exceptions to other monads, in the same way
@@ -52,16 +52,15 @@ mapExceptT f (ExceptT m) = ExceptT (f m)
52
52
except :: forall e m a . Applicative m => Either e a -> ExceptT e m a
53
53
except = ExceptT <<< pure
54
54
55
+ derive instance newtypeExceptT :: Newtype (ExceptT e m a ) _
56
+
55
57
instance functorExceptT :: Functor m => Functor (ExceptT e m ) where
56
58
map f = mapExceptT (map (map f))
57
59
58
- instance applyExceptT :: Apply m => Apply (ExceptT e m ) where
59
- apply (ExceptT f) (ExceptT x) =
60
- let f' = apply <$> f
61
- x' = f' <*> x
62
- in ExceptT x'
60
+ instance applyExceptT :: Monad m => Apply (ExceptT e m ) where
61
+ apply = ap
63
62
64
- instance applicativeExceptT :: Applicative m => Applicative (ExceptT e m ) where
63
+ instance applicativeExceptT :: Monad m => Applicative (ExceptT e m ) where
65
64
pure = ExceptT <<< pure <<< Right
66
65
67
66
instance bindExceptT :: Monad m => Bind (ExceptT e m ) where
@@ -116,15 +115,19 @@ instance monadErrorExceptT :: Monad m => MonadError e (ExceptT e m) where
116
115
catchError (ExceptT m) k =
117
116
ExceptT (m >>= either (\a -> case k a of ExceptT b -> b) (pure <<< Right ))
118
117
119
- instance monadReaderExceptT :: MonadReader r m => MonadReader r (ExceptT e m ) where
118
+ instance monadAskExceptT :: MonadAsk r m => MonadAsk r (ExceptT e m ) where
120
119
ask = lift ask
120
+
121
+ instance monadReaderExceptT :: MonadReader r m => MonadReader r (ExceptT e m ) where
121
122
local f = mapExceptT (local f)
122
123
123
124
instance monadStateExceptT :: MonadState s m => MonadState s (ExceptT e m ) where
124
125
state f = lift (state f)
125
126
127
+ instance monadTellExceptT :: MonadTell w m => MonadTell w (ExceptT e m ) where
128
+ tell = lift <<< tell
129
+
126
130
instance monadWriterExceptT :: MonadWriter w m => MonadWriter w (ExceptT e m ) where
127
- writer wd = lift (writer wd)
128
131
listen = mapExceptT \m -> do
129
132
Tuple a w <- listen m
130
133
pure $ (\r -> Tuple r w) <$> a
@@ -133,5 +136,3 @@ instance monadWriterExceptT :: MonadWriter w m => MonadWriter w (ExceptT e m) wh
133
136
pure case a of
134
137
Left e -> Tuple (Left e) id
135
138
Right (Tuple r f) -> Tuple (Right r) f
136
-
137
- instance monadRWSExceptT :: MonadRWS r w s m => MonadRWS r w s (ExceptT e m )
0 commit comments