22
33module Control.Monad.Except.Trans
44 ( ExceptT (..), runExceptT , withExceptT , mapExceptT , except
5- , module Control.Monad.Trans
5+ , module Control.Monad.Trans.Class
66 , module Control.Monad.Error.Class
77 ) where
88
@@ -13,18 +13,18 @@ import Control.Alternative (class Alternative)
1313import Control.Monad.Cont.Class (class MonadCont , callCC )
1414import Control.Monad.Eff.Class (class MonadEff , liftEff )
1515import 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 )
1717import Control.Monad.Rec.Class (class MonadRec , tailRecM , Step (..))
18- import Control.Monad.RWS.Class (class MonadRWS )
1918import 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 )
2221import Control.MonadPlus (class MonadPlus )
2322import Control.MonadZero (class MonadZero )
2423import Control.Plus (class Plus )
2524
2625import Data.Either (Either (..), either )
2726import Data.Monoid (class Monoid , mempty )
27+ import Data.Newtype (class Newtype )
2828import Data.Tuple (Tuple (..))
2929
3030-- | A monad transformer which adds exceptions to other monads, in the same way
@@ -52,16 +52,15 @@ mapExceptT f (ExceptT m) = ExceptT (f m)
5252except :: forall e m a . Applicative m => Either e a -> ExceptT e m a
5353except = ExceptT <<< pure
5454
55+ derive instance newtypeExceptT :: Newtype (ExceptT e m a ) _
56+
5557instance functorExceptT :: Functor m => Functor (ExceptT e m ) where
5658 map f = mapExceptT (map (map f))
5759
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
6362
64- instance applicativeExceptT :: Applicative m => Applicative (ExceptT e m ) where
63+ instance applicativeExceptT :: Monad m => Applicative (ExceptT e m ) where
6564 pure = ExceptT <<< pure <<< Right
6665
6766instance bindExceptT :: Monad m => Bind (ExceptT e m ) where
@@ -116,15 +115,19 @@ instance monadErrorExceptT :: Monad m => MonadError e (ExceptT e m) where
116115 catchError (ExceptT m) k =
117116 ExceptT (m >>= either (\a -> case k a of ExceptT b -> b) (pure <<< Right ))
118117
119- instance monadReaderExceptT :: MonadReader r m => MonadReader r (ExceptT e m ) where
118+ instance monadAskExceptT :: MonadAsk r m => MonadAsk r (ExceptT e m ) where
120119 ask = lift ask
120+
121+ instance monadReaderExceptT :: MonadReader r m => MonadReader r (ExceptT e m ) where
121122 local f = mapExceptT (local f)
122123
123124instance monadStateExceptT :: MonadState s m => MonadState s (ExceptT e m ) where
124125 state f = lift (state f)
125126
127+ instance monadTellExceptT :: MonadTell w m => MonadTell w (ExceptT e m ) where
128+ tell = lift <<< tell
129+
126130instance monadWriterExceptT :: MonadWriter w m => MonadWriter w (ExceptT e m ) where
127- writer wd = lift (writer wd)
128131 listen = mapExceptT \m -> do
129132 Tuple a w <- listen m
130133 pure $ (\r -> Tuple r w) <$> a
@@ -133,5 +136,3 @@ instance monadWriterExceptT :: MonadWriter w m => MonadWriter w (ExceptT e m) wh
133136 pure case a of
134137 Left e -> Tuple (Left e) id
135138 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