on master help sign in
Use liftListen and liftPass from transformers-lift
commitabfee98f489612f798faef82d64e17d8a3385994 authorIndex Int <vlad.z.4096@gmail.com> dateFri 19 Jun 2015, 13:44 (11 years ago) parent690bc44
16 files changed+84−250
src/Control/Ether/Util.hs+1−15 src/Control/Monad/Ether/Except.hs−1 src/Control/Monad/Ether/Implicit/Except.hs−6 src/Control/Monad/Ether/Implicit/Reader.hs−5 src/Control/Monad/Ether/Implicit/State/Lazy.hs−5 src/Control/Monad/Ether/Implicit/State/Strict.hs−5 src/Control/Monad/Ether/Reader.hs−1 src/Control/Monad/Ether/State/Lazy.hs−1 src/Control/Monad/Ether/State/Strict.hs−1 src/Control/Monad/Ether/Writer.hs−1 src/Control/Monad/Ether/Writer/Class.hs+12−92 src/Control/Monad/Trans/Ether/Except.hs+14−26 src/Control/Monad/Trans/Ether/Reader.hs+15−27 src/Control/Monad/Trans/Ether/State/Lazy.hs+14−22 src/Control/Monad/Trans/Ether/State/Strict.hs+14−22 src/Control/Monad/Trans/Ether/Writer.hs+14−20
src/Control/Ether/Util.hs+1−15
@@ -4,9 +4,7 @@
44{-# LANGUAGE TypeOperators #-}
55{-# LANGUAGE TypeFamilies #-}
66module Control.Ether.Util
7− ( liftListen_WriterT
8− , liftPass_WriterT
9− , type (++)
7+ ( type (++)
108 , MaybeToList
119 , fmap
1210 ) where
@@ -29,18 +27,6 @@ type family MaybeToList (mt :: Maybe k) :: [k] where
2927 MaybeToList 'Nothing = '[]
3028 MaybeToList ('Just t) = '[t]
3129
32−-- TODO: Not sure if correct
33−liftListen_WriterT :: Monad m => Sig.Listen w' m (a, w) -> Sig.Listen w' (Trans.WriterT w m) a
34−liftListen_WriterT listen m = Trans.WriterT $ do
35− ~((a, w'), w) <- listen (Trans.runWriterT m)
36− return ((a, w), w')
37−
38−-- TODO: Not sure if correct
39−liftPass_WriterT :: Monad m => Sig.Pass w' m (a, w) -> Sig.Pass w' (Trans.WriterT w m) a
40−liftPass_WriterT pass m = Trans.WriterT $ pass $ do
41− ~((a, f), w) <- Trans.runWriterT m
42− return ((a, w), f)
43−
4430#if __GLASGOW_HASKELL__ < 710
4531fmap :: Monad f => (a -> b) -> f a -> f b
4632fmap = Control.Monad.liftM
src/Control/Monad/Ether/Except.hs−1
@@ -12,7 +12,6 @@ module Control.Monad.Ether.Except
1212 , ExceptT
1313 , exceptT
1414 , runExceptT
15− , mapExceptT
1615 -- * Handle functions
1716 , handleT
1817 , handle
src/Control/Monad/Ether/Implicit/Except.hs−6
@@ -16,7 +16,6 @@ module Control.Monad.Ether.Implicit.Except
1616 , ExceptT
1717 , exceptT
1818 , runExceptT
19− , mapExceptT
2019 -- * Handle functions
2120 , handle
2221 , handleT
@@ -54,11 +53,6 @@ exceptT = Explicit.exceptT Proxy
5453runExceptT :: ExceptT e m a -> m (Either e a)
5554runExceptT = Explicit.runExceptT Proxy
5655
57−-- | See 'Control.Monad.Ether.Except.mapExceptT'.
58−-- Note that due to implicit tagging the exception type cannot be changed.
59−mapExceptT :: (m (Either e a) -> n (Either e b)) -> ExceptT e m a -> ExceptT e n b
60−mapExceptT = Explicit.mapExceptT Proxy
61−
6256-- | See 'Control.Monad.Ether.Except.handle'.
6357handle :: (e -> a) -> Except e a -> a
6458handle = Explicit.handle (Proxy :: Proxy e)
src/Control/Monad/Ether/Implicit/Reader.hs−5
@@ -18,7 +18,6 @@ module Control.Monad.Ether.Implicit.Reader
1818 , ReaderT
1919 , readerT
2020 , runReaderT
21− , mapReaderT
2221 ) where
2322
2423import Data.Proxy
@@ -42,10 +41,6 @@ runReaderT = Explicit.runReaderT Proxy
4241runReader :: Reader r a -> r -> a
4342runReader = Explicit.runReader Proxy
4443
45−-- | See 'Control.Monad.Ether.Reader.mapReaderT'.
46−mapReaderT :: (m a -> n b) -> ReaderT r m a -> ReaderT r n b
47−mapReaderT = Explicit.mapReaderT Proxy
48−
4944-- | See 'Control.Monad.Ether.Reader.MonadReader'.
5045type MonadReader r = Explicit.MonadReader r r
5146
src/Control/Monad/Ether/Implicit/State/Lazy.hs−5
@@ -23,7 +23,6 @@ module Control.Monad.Ether.Implicit.State.Lazy
2323 , runStateT
2424 , evalStateT
2525 , execStateT
26− , mapStateT
2726 ) where
2827
2928import Data.Proxy
@@ -63,10 +62,6 @@ execStateT = Explicit.execStateT Proxy
6362execState :: State s a -> s -> s
6463execState = Explicit.execState Proxy
6564
66−-- | See 'Control.Monad.Ether.State.Lazy.mapStateT'.
67−mapStateT :: (m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b
68−mapStateT = Explicit.mapStateT Proxy
69−
7065-- | See 'Control.Monad.Ether.State.Lazy.MonadState'.
7166type MonadState s = Explicit.MonadState s s
7267
src/Control/Monad/Ether/Implicit/State/Strict.hs−5
@@ -23,7 +23,6 @@ module Control.Monad.Ether.Implicit.State.Strict
2323 , runStateT
2424 , evalStateT
2525 , execStateT
26− , mapStateT
2726 ) where
2827
2928import Data.Proxy
@@ -63,10 +62,6 @@ execStateT = Explicit.execStateT Proxy
6362execState :: State s a -> s -> s
6463execState = Explicit.execState Proxy
6564
66−-- | See 'Control.Monad.Ether.State.Strict.mapStateT'.
67−mapStateT :: (m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b
68−mapStateT = Explicit.mapStateT Proxy
69−
7065-- | See 'Control.Monad.Ether.State.Strict.MonadState'.
7166type MonadState s = Explicit.MonadState s s
7267
src/Control/Monad/Ether/Reader.hs−1
@@ -13,7 +13,6 @@ module Control.Monad.Ether.Reader
1313 , ReaderT
1414 , readerT
1515 , runReaderT
16− , mapReaderT
1716 ) where
1817
1918import Control.Monad.Ether.Reader.Class
src/Control/Monad/Ether/State/Lazy.hs−1
@@ -18,7 +18,6 @@ module Control.Monad.Ether.State.Lazy
1818 , runStateT
1919 , evalStateT
2020 , execStateT
21− , mapStateT
2221 ) where
2322
2423import Control.Monad.Ether.State.Class
src/Control/Monad/Ether/State/Strict.hs−1
@@ -18,7 +18,6 @@ module Control.Monad.Ether.State.Strict
1818 , runStateT
1919 , evalStateT
2020 , execStateT
21− , mapStateT
2221 ) where
2322
2423import Control.Monad.Ether.State.Class
src/Control/Monad/Ether/Writer.hs−1
@@ -16,7 +16,6 @@ module Control.Monad.Ether.Writer
1616 , writerT
1717 , runWriterT
1818 , execWriterT
19− , mapWriterT
2019 ) where
2120
2221import Control.Monad.Ether.Writer.Class
src/Control/Monad/Ether/Writer/Class.hs+12−92
@@ -22,25 +22,10 @@ module Control.Monad.Ether.Writer.Class
2222import Data.Monoid
2323#endif
2424
25−import Data.Proxy (Proxy(Proxy))
26−import Control.Monad.Trans (lift)
27−
2825import Control.Monad.Trans.Ether.Writer hiding (writer, tell, listen, pass)
29−import qualified Control.Monad.Trans.Ether.Reader as R
30−import qualified Control.Monad.Trans.Ether.State.Lazy as S.L
31−import qualified Control.Monad.Trans.Ether.State.Strict as S.S
32−import qualified Control.Monad.Trans.Ether.Except as E
3326import qualified Control.Monad.Trans.Ether.Writer as W
34−import qualified Control.Ether.Util as Util
35−
36−-- for mtl instances
37−import qualified Control.Monad.Trans.Except as Trans.E
38−import qualified Control.Monad.Trans.Identity as Trans.I
39−import qualified Control.Monad.Trans.Maybe as Trans.M
40−import qualified Control.Monad.Trans.Reader as Trans.R
41−import qualified Control.Monad.Trans.State.Lazy as Trans.S.Lazy
42−import qualified Control.Monad.Trans.State.Strict as Trans.S.Strict
43−import qualified Control.Monad.Trans.Writer.Lazy as Trans.W.Lazy
27+import qualified Control.Monad.Trans.Lift.Listen as Lift
28+import qualified Control.Monad.Trans.Lift.Pass as Lift
4429
4530-- | See 'Control.Monad.Writer.MonadWriter'.
4631class (Monoid w, Monad m) => MonadWriter tag w m | m tag -> w where
@@ -84,78 +69,13 @@ instance {-# OVERLAPPING #-} (Monoid w, Monad m) => MonadWriter tag w (WriterT t
8469 listen = W.listen
8570 pass = W.pass
8671
87−instance (Monoid w', MonadWriter tag w m) => MonadWriter tag w (WriterT tag' w' m) where
88− writer t = lift . writer t
89− tell t = lift . tell t
90− listen t = W.liftListen Proxy (listen t)
91− pass t = W.liftPass Proxy (pass t)
92−
93−-- Instances for other tagged transformers
94−
95−instance (MonadWriter tag w m) => MonadWriter tag w (R.ReaderT tag' r m) where
96− writer t = lift . writer t
97− tell t = lift . tell t
98− listen t = R.mapReaderT Proxy (listen t)
99− pass t = R.mapReaderT Proxy (pass t)
100−
101−instance (MonadWriter tag w m) => MonadWriter tag w (E.ExceptT tag' e m) where
102− writer t = lift . writer t
103− tell t = lift . tell t
104− listen t = E.liftListen Proxy (listen t)
105− pass t = E.liftPass Proxy (pass t)
106−
107−instance (MonadWriter tag w m) => MonadWriter tag w (S.L.StateT tag' e m) where
108− writer t = lift . writer t
109− tell t = lift . tell t
110− listen t = S.L.liftListen Proxy (listen t)
111− pass t = S.L.liftPass Proxy (pass t)
112−
113−instance (MonadWriter tag w m) => MonadWriter tag w (S.S.StateT tag' e m) where
114− writer t = lift . writer t
115− tell t = lift . tell t
116− listen t = S.S.liftListen Proxy (listen t)
117− pass t = S.S.liftPass Proxy (pass t)
118−
119−-- Instances for mtl transformers
120−
121−instance (MonadWriter tag w m) => MonadWriter tag w (Trans.E.ExceptT e m) where
122− writer t = lift . writer t
123− tell t = lift . tell t
124− listen t = Trans.E.liftListen (listen t)
125− pass t = Trans.E.liftPass (pass t)
126−
127−instance (MonadWriter tag w m) => MonadWriter tag w (Trans.I.IdentityT m) where
128− writer t = lift . writer t
129− tell t = lift . tell t
130− listen t = Trans.I.mapIdentityT (listen t)
131− pass t = Trans.I.mapIdentityT (pass t)
132−
133−instance (MonadWriter tag w m) => MonadWriter tag w (Trans.M.MaybeT m) where
134− writer t = lift . writer t
135− tell t = lift . tell t
136− listen t = Trans.M.liftListen (listen t)
137− pass t = Trans.M.liftPass (pass t)
138−
139−instance (MonadWriter tag w m) => MonadWriter tag w (Trans.R.ReaderT r m) where
140− writer t = lift . writer t
141− tell t = lift . tell t
142− listen t = Trans.R.mapReaderT (listen t)
143− pass t = Trans.R.mapReaderT (pass t)
144−
145−instance (MonadWriter tag w m) => MonadWriter tag w (Trans.S.Lazy.StateT s m) where
146− writer t = lift . writer t
147− tell t = lift . tell t
148− listen t = Trans.S.Lazy.liftListen (listen t)
149− pass t = Trans.S.Lazy.liftPass (pass t)
150−
151−instance (MonadWriter tag w m) => MonadWriter tag w (Trans.S.Strict.StateT s m) where
152− writer t = lift . writer t
153− tell t = lift . tell t
154− listen t = Trans.S.Strict.liftListen (listen t)
155− pass t = Trans.S.Strict.liftPass (pass t)
156−
157−instance (Monoid w', MonadWriter tag w m) => MonadWriter tag w (Trans.W.Lazy.WriterT w' m) where
158− writer t = lift . writer t
159− tell t = lift . tell t
160− listen t = Util.liftListen_WriterT (listen t)
161− pass t = Util.liftPass_WriterT (pass t)
72+instance ( Lift.LiftListen t
73+ , Lift.LiftPass t
74+ , Monad (t m)
75+ , MonadWriter tag w m
76+ , Monoid w
77+ ) => MonadWriter tag w (t m) where
78+ writer t = Lift.lift . writer t
79+ tell t = Lift.lift . tell t
80+ listen t = Lift.liftListen (listen t)
81+ pass t = Lift.liftPass (pass t)
src/Control/Monad/Trans/Ether/Except.hs+14−26
@@ -18,14 +18,11 @@ module Control.Monad.Trans.Ether.Except
1818 , ExceptT
1919 , exceptT
2020 , runExceptT
21− , mapExceptT
2221 -- * Exception operations
2322 , throw
2423 , catch
2524 -- * Lifting other operations
2625 , liftCallCC
27− , liftListen
28− , liftPass
2926 ) where
3027
3128import Data.Proxy (Proxy(Proxy))
@@ -44,8 +41,11 @@ import qualified Control.Newtype as NT
4441import qualified Control.Monad.Signatures as Sig
4542import qualified Control.Monad.Trans.Control as MC
4643import qualified Control.Monad.Trans.Except as Trans
47−import qualified Control.Monad.Trans.Lift.Local as Lift
48−import qualified Control.Monad.Trans.Lift.Catch as Lift
44+
45+import qualified Control.Monad.Trans.Lift.Local as Lift
46+import qualified Control.Monad.Trans.Lift.Catch as Lift
47+import qualified Control.Monad.Trans.Lift.Listen as Lift
48+import qualified Control.Monad.Trans.Lift.Pass as Lift
4949
5050import qualified Control.Monad.Cont.Class as Class
5151import qualified Control.Monad.Reader.Class as Class
@@ -86,6 +86,12 @@ instance MC.MonadTransControl (ExceptT tag e) where
8686instance Lift.LiftLocal (ExceptT tag e)
8787instance Lift.LiftCatch (ExceptT tag e)
8888
89+instance Lift.LiftListen (ExceptT tag e) where
90+ liftListen listen m = ExceptT $ Lift.liftListen listen (coerce m)
91+
92+instance Lift.LiftPass (ExceptT tag e) where
93+ liftPass pass m = ExceptT $ Lift.liftPass pass (coerce m)
94+
8995instance Taggable (ExceptT tag e m) where
9096 type Tag (ExceptT tag e m) = 'Just tag
9197 type Inner (ExceptT tag e m) = 'Just m
@@ -106,16 +112,6 @@ except t = exceptT t . return
106112runExceptT :: proxy tag -> ExceptT tag e m a -> m (Either e a)
107113runExceptT t = Trans.runExceptT . untagged t
108114
109−-- | Transforms the computation inside an 'ExceptT'.
110−--
111−-- * @'runExceptT' tag ('mapExceptT' tag f m) = f ('runExceptT' tag m)@
112−mapExceptT
113− :: proxy tag
114− -> (m (Either e a) -> n (Either e' b))
115− -> ExceptT tag e m a
116− -> ExceptT tag e' n b
117−mapExceptT t f m = tagged t $ Trans.mapExceptT f (coerce m)
118−
119115-- | Is used within a monadic computation to begin exception processing.
120116throw :: Monad m => proxy tag -> e -> ExceptT tag e m a
121117throw t = tagged t . Trans.throwE
@@ -128,20 +124,12 @@ catch t m h = tagged t $ Trans.catchE (coerce m) (coerce . h)
128124liftCallCC :: proxy tag -> Sig.CallCC m (Either e a) (Either e b) -> Sig.CallCC (ExceptT tag e m) a b
129125liftCallCC t callCC f = tagged t $ Trans.liftCallCC callCC (coerce f)
130126
131−-- | Lift a @listen@ operation to the new monad.
132−liftListen :: Monad m => proxy tag -> Sig.Listen w m (Either e a) -> Sig.Listen w (ExceptT tag e m) a
133−liftListen t listen m = tagged t $ Trans.liftListen listen (coerce m)
134−
135−-- | Lift a @pass@ operation to the new monad.
136−liftPass :: Monad m => proxy tag -> Sig.Pass w m (Either e a) -> Sig.Pass w (ExceptT tag e m) a
137−liftPass t pass m = tagged t $ Trans.liftPass pass (coerce m)
138−
139127instance Class.MonadCont m => Class.MonadCont (ExceptT tag e m) where
140128 callCC = liftCallCC Proxy Class.callCC
141129
142130instance Class.MonadReader r m => Class.MonadReader r (ExceptT tag e m) where
143131 ask = lift Class.ask
144− local = mapExceptT Proxy . Class.local
132+ local = Lift.liftLocal Class.ask Class.local
145133 reader = lift . Class.reader
146134
147135instance Class.MonadState s m => Class.MonadState s (ExceptT tag e m) where
@@ -152,8 +140,8 @@ instance Class.MonadState s m => Class.MonadState s (ExceptT tag e m) where
152140instance Class.MonadWriter w m => Class.MonadWriter w (ExceptT tag e m) where
153141 writer = lift . Class.writer
154142 tell = lift . Class.tell
155− listen = liftListen Proxy Class.listen
156− pass = liftPass Proxy Class.pass
143+ listen = Lift.liftListen Class.listen
144+ pass = Lift.liftPass Class.pass
157145
158146instance Class.MonadError e' m => Class.MonadError e' (ExceptT tag e m) where
159147 throwError = lift . Class.throwError
src/Control/Monad/Trans/Ether/Reader.hs+15−27
@@ -18,8 +18,6 @@ module Control.Monad.Trans.Ether.Reader
1818 , ReaderT
1919 , readerT
2020 , runReaderT
21− , mapReaderT
22− , withReaderT
2321 -- * Reader operations
2422 , ask
2523 , local
@@ -43,8 +41,11 @@ import qualified Control.Newtype as NT
4341import qualified Control.Monad.Signatures as Sig
4442import qualified Control.Monad.Trans.Control as MC
4543import qualified Control.Monad.Trans.Reader as Trans
46−import qualified Control.Monad.Trans.Lift.Local as Lift
47−import qualified Control.Monad.Trans.Lift.Catch as Lift
44+
45+import qualified Control.Monad.Trans.Lift.Local as Lift
46+import qualified Control.Monad.Trans.Lift.Catch as Lift
47+import qualified Control.Monad.Trans.Lift.Listen as Lift
48+import qualified Control.Monad.Trans.Lift.Pass as Lift
4849
4950import qualified Control.Monad.Cont.Class as Class
5051import qualified Control.Monad.Reader.Class as Class
@@ -80,6 +81,12 @@ instance MC.MonadTransControl (ReaderT tag r) where
8081instance Lift.LiftLocal (ReaderT tag r)
8182instance Lift.LiftCatch (ReaderT tag r)
8283
84+instance Lift.LiftListen (ReaderT tag r) where
85+ liftListen listen m = ReaderT $ Lift.liftListen listen (coerce m)
86+
87+instance Lift.LiftPass (ReaderT tag r) where
88+ liftPass pass m = ReaderT $ Lift.liftPass pass (coerce m)
89+
8390instance Taggable (ReaderT tag r m) where
8491 type Tag (ReaderT tag r m) = 'Just tag
8592 type Inner (ReaderT tag r m) = 'Just m
@@ -106,25 +113,6 @@ runReaderT t = Trans.runReaderT . untagged t
106113runReader :: proxy tag -> Reader tag r a -> r -> a
107114runReader t = Trans.runReader . untagged t
108115
109−-- | Transform the computation inside a 'ReaderT'.
110−--
111−-- * @'runReaderT' tag ('mapReaderT' tag f m) = f . 'runReaderT' tag m@
112−mapReaderT :: proxy tag -> (m a -> n b) -> ReaderT tag r m a -> ReaderT tag r n b
113−mapReaderT t f m = tagged t $ Trans.mapReaderT f (coerce m)
114−
115−-- | Execute a computation in a modified environment
116−-- (a more general version of 'local').
117−--
118−-- * @'runReaderT' tag ('withReaderT' tag f m) = 'runReaderT' tag m . f@
119−withReaderT
120− :: proxy tag
121− -> (r' -> r)
122− -- ^ The function to modify the environment.
123− -> ReaderT tag r m a
124− -- ^ Computation to run in the modified environment.
125− -> ReaderT tag r' m a
126−withReaderT t f m = tagged t $ Trans.withReaderT f (coerce m)
127−
128116-- | Lift a @callCC@ operation to the new monad.
129117liftCallCC :: proxy tag -> Sig.CallCC m a b -> Sig.CallCC (ReaderT tag r m) a b
130118liftCallCC t callCC f = tagged t $ Trans.liftCallCC callCC (coerce f)
@@ -144,7 +132,7 @@ local
144132 -> ReaderT tag r m a
145133 -- ^ Computation to run in the modified environment.
146134 -> ReaderT tag r m a
147−local = withReaderT
135+local t f m = tagged t $ Trans.withReaderT f (coerce m)
148136
149137-- Instances for mtl classes
150138
@@ -153,7 +141,7 @@ instance Class.MonadCont m => Class.MonadCont (ReaderT tag r m) where
153141
154142instance Class.MonadReader r' m => Class.MonadReader r' (ReaderT tag r m) where
155143 ask = lift Class.ask
156− local = mapReaderT Proxy . Class.local
144+ local = Lift.liftLocal Class.ask Class.local
157145 reader = lift . Class.reader
158146
159147instance Class.MonadState s m => Class.MonadState s (ReaderT tag r m) where
@@ -164,8 +152,8 @@ instance Class.MonadState s m => Class.MonadState s (ReaderT tag r m) where
164152instance Class.MonadWriter w m => Class.MonadWriter w (ReaderT tag r m) where
165153 writer = lift . Class.writer
166154 tell = lift . Class.tell
167− listen = mapReaderT Proxy Class.listen
168− pass = mapReaderT Proxy Class.pass
155+ listen = Lift.liftListen Class.listen
156+ pass = Lift.liftPass Class.pass
169157
170158instance Class.MonadError e m => Class.MonadError e (ReaderT tag r m) where
171159 throwError = lift . Class.throwError
src/Control/Monad/Trans/Ether/State/Lazy.hs+14−22
@@ -22,14 +22,11 @@ module Control.Monad.Trans.Ether.State.Lazy
2222 , runStateT
2323 , evalStateT
2424 , execStateT
25− , mapStateT
2625 -- * State operations
2726 , get
2827 , put
2928 -- * Litfing other operations
3029 , liftCallCC'
31− , liftListen
32− , liftPass
3330 ) where
3431
3532import Data.Proxy (Proxy(Proxy))
@@ -48,8 +45,11 @@ import qualified Control.Newtype as NT
4845import qualified Control.Monad.Signatures as Sig
4946import qualified Control.Monad.Trans.Control as MC
5047import qualified Control.Monad.Trans.State.Lazy as Trans
51−import qualified Control.Monad.Trans.Lift.Local as Lift
52−import qualified Control.Monad.Trans.Lift.Catch as Lift
48+
49+import qualified Control.Monad.Trans.Lift.Local as Lift
50+import qualified Control.Monad.Trans.Lift.Catch as Lift
51+import qualified Control.Monad.Trans.Lift.Listen as Lift
52+import qualified Control.Monad.Trans.Lift.Pass as Lift
5353
5454import qualified Control.Monad.Cont.Class as Class
5555import qualified Control.Monad.Reader.Class as Class
@@ -85,6 +85,12 @@ instance MC.MonadTransControl (StateT tag s) where
8585instance Lift.LiftLocal (StateT tag s)
8686instance Lift.LiftCatch (StateT tag s)
8787
88+instance Lift.LiftListen (StateT tag s) where
89+ liftListen listen m = StateT $ Lift.liftListen listen (coerce m)
90+
91+instance Lift.LiftPass (StateT tag s) where
92+ liftPass pass m = StateT $ Lift.liftPass pass (coerce m)
93+
8894instance Taggable (StateT tag s m) where
8995 type Tag (StateT tag s m) = 'Just tag
9096 type Inner (StateT tag s m) = 'Just m
@@ -131,12 +137,6 @@ evalState t = Trans.evalState . untagged t
131137execState :: proxy tag -> State tag s a -> s -> s
132138execState t = Trans.execState . untagged t
133139
134−-- | Transform the computation inside a 'StateT'.
135−--
136−-- * @'runStateT' tag ('mapStateT' tag f m) = f . 'runStateT' tag m@
137−mapStateT :: proxy tag -> (m (a, s) -> n (b, s)) -> StateT tag s m a -> StateT tag s n b
138−mapStateT t f m = tagged t $ Trans.mapStateT f (coerce m)
139−
140140-- | Fetch the current value of the state within the monad.
141141get :: Monad m => proxy tag -> StateT tag s m s
142142get t = tagged t Trans.get
@@ -145,20 +145,12 @@ get t = tagged t Trans.get
145145put :: Monad m => proxy tag -> s -> StateT tag s m ()
146146put t = tagged t . Trans.put
147147
148−-- | Lift a @listen@ operation to the new monad.
149−liftListen :: Monad m => proxy tag -> Sig.Listen w m (a, s) -> Sig.Listen w (StateT tag s m) a
150−liftListen t listen m = tagged t $ Trans.liftListen listen (coerce m)
151−
152148-- | In-situ lifting of a @callCC@ operation to the new monad.
153149-- This version uses the current state on entering the continuation.
154150-- It does not satisfy the uniformity property (see "Control.Monad.Signatures").
155151liftCallCC' :: proxy tag -> Sig.CallCC m (a, s) (b, s) -> Sig.CallCC (StateT tag s m) a b
156152liftCallCC' t callCC f = tagged t $ Trans.liftCallCC' callCC (coerce f)
157153
158−-- | Lift a @pass@ operation to the new monad.
159−liftPass :: Monad m => proxy tag -> Sig.Pass w m (a,s) -> Sig.Pass w (StateT tag s m) a
160−liftPass t pass m = tagged t $ Trans.liftPass pass (coerce m)
161−
162154-- Instances for mtl classes
163155
164156instance Class.MonadCont m => Class.MonadCont (StateT tag s m) where
@@ -166,7 +158,7 @@ instance Class.MonadCont m => Class.MonadCont (StateT tag s m) where
166158
167159instance Class.MonadReader r m => Class.MonadReader r (StateT tag s m) where
168160 ask = lift Class.ask
169− local = mapStateT Proxy . Class.local
161+ local = Lift.liftLocal Class.ask Class.local
170162 reader = lift . Class.reader
171163
172164instance Class.MonadState s' m => Class.MonadState s' (StateT tag s m) where
@@ -177,8 +169,8 @@ instance Class.MonadState s' m => Class.MonadState s' (StateT tag s m) where
177169instance Class.MonadWriter w m => Class.MonadWriter w (StateT tag s m) where
178170 writer = lift . Class.writer
179171 tell = lift . Class.tell
180− listen = liftListen Proxy Class.listen
181− pass = liftPass Proxy Class.pass
172+ listen = Lift.liftListen Class.listen
173+ pass = Lift.liftPass Class.pass
182174
183175instance Class.MonadError e m => Class.MonadError e (StateT tag s m) where
184176 throwError = lift . Class.throwError
src/Control/Monad/Trans/Ether/State/Strict.hs+14−22
@@ -22,14 +22,11 @@ module Control.Monad.Trans.Ether.State.Strict
2222 , runStateT
2323 , evalStateT
2424 , execStateT
25− , mapStateT
2625 -- * State operations
2726 , get
2827 , put
2928 -- * Litfing other operations
3029 , liftCallCC'
31− , liftListen
32− , liftPass
3330 ) where
3431
3532import Data.Proxy (Proxy(Proxy))
@@ -48,8 +45,11 @@ import qualified Control.Newtype as NT
4845import qualified Control.Monad.Signatures as Sig
4946import qualified Control.Monad.Trans.Control as MC
5047import qualified Control.Monad.Trans.State.Strict as Trans
51−import qualified Control.Monad.Trans.Lift.Local as Lift
52−import qualified Control.Monad.Trans.Lift.Catch as Lift
48+
49+import qualified Control.Monad.Trans.Lift.Local as Lift
50+import qualified Control.Monad.Trans.Lift.Catch as Lift
51+import qualified Control.Monad.Trans.Lift.Listen as Lift
52+import qualified Control.Monad.Trans.Lift.Pass as Lift
5353
5454import qualified Control.Monad.Cont.Class as Class
5555import qualified Control.Monad.Reader.Class as Class
@@ -85,6 +85,12 @@ instance MC.MonadTransControl (StateT tag s) where
8585instance Lift.LiftLocal (StateT tag s)
8686instance Lift.LiftCatch (StateT tag s)
8787
88+instance Lift.LiftListen (StateT tag s) where
89+ liftListen listen m = StateT $ Lift.liftListen listen (coerce m)
90+
91+instance Lift.LiftPass (StateT tag s) where
92+ liftPass pass m = StateT $ Lift.liftPass pass (coerce m)
93+
8894instance Taggable (StateT tag s m) where
8995 type Tag (StateT tag s m) = 'Just tag
9096 type Inner (StateT tag s m) = 'Just m
@@ -131,12 +137,6 @@ evalState t = Trans.evalState . untagged t
131137execState :: proxy tag -> State tag s a -> s -> s
132138execState t = Trans.execState . untagged t
133139
134−-- | Transform the computation inside a 'StateT'.
135−--
136−-- * @'runStateT' tag ('mapStateT' tag f m) = f . 'runStateT' tag m@
137−mapStateT :: proxy tag -> (m (a, s) -> n (b, s)) -> StateT tag s m a -> StateT tag s n b
138−mapStateT t f m = tagged t $ Trans.mapStateT f (coerce m)
139−
140140-- | Fetch the current value of the state within the monad.
141141get :: Monad m => proxy tag -> StateT tag s m s
142142get t = tagged t Trans.get
@@ -145,20 +145,12 @@ get t = tagged t Trans.get
145145put :: Monad m => proxy tag -> s -> StateT tag s m ()
146146put t = tagged t . Trans.put
147147
148−-- | Lift a @listen@ operation to the new monad.
149−liftListen :: Monad m => proxy tag -> Sig.Listen w m (a, s) -> Sig.Listen w (StateT tag s m) a
150−liftListen t listen m = tagged t $ Trans.liftListen listen (coerce m)
151−
152148-- | In-situ lifting of a @callCC@ operation to the new monad.
153149-- This version uses the current state on entering the continuation.
154150-- It does not satisfy the uniformity property (see "Control.Monad.Signatures").
155151liftCallCC' :: proxy tag -> Sig.CallCC m (a, s) (b, s) -> Sig.CallCC (StateT tag s m) a b
156152liftCallCC' t callCC f = tagged t $ Trans.liftCallCC' callCC (coerce f)
157153
158−-- | Lift a @pass@ operation to the new monad.
159−liftPass :: Monad m => proxy tag -> Sig.Pass w m (a,s) -> Sig.Pass w (StateT tag s m) a
160−liftPass t pass m = tagged t $ Trans.liftPass pass (coerce m)
161−
162154-- Instances for mtl classes
163155
164156instance Class.MonadCont m => Class.MonadCont (StateT tag s m) where
@@ -166,7 +158,7 @@ instance Class.MonadCont m => Class.MonadCont (StateT tag s m) where
166158
167159instance Class.MonadReader r m => Class.MonadReader r (StateT tag s m) where
168160 ask = lift Class.ask
169− local = mapStateT Proxy . Class.local
161+ local = Lift.liftLocal Class.ask Class.local
170162 reader = lift . Class.reader
171163
172164instance Class.MonadState s' m => Class.MonadState s' (StateT tag s m) where
@@ -177,8 +169,8 @@ instance Class.MonadState s' m => Class.MonadState s' (StateT tag s m) where
177169instance Class.MonadWriter w m => Class.MonadWriter w (StateT tag s m) where
178170 writer = lift . Class.writer
179171 tell = lift . Class.tell
180− listen = liftListen Proxy Class.listen
181− pass = liftPass Proxy Class.pass
172+ listen = Lift.liftListen Class.listen
173+ pass = Lift.liftPass Class.pass
182174
183175instance Class.MonadError e m => Class.MonadError e (StateT tag s m) where
184176 throwError = lift . Class.throwError
src/Control/Monad/Trans/Ether/Writer.hs+14−20
@@ -21,15 +21,12 @@ module Control.Monad.Trans.Ether.Writer
2121 , writerT
2222 , runWriterT
2323 , execWriterT
24− , mapWriterT
2524 -- * Writer operations
2625 , tell
2726 , listen
2827 , pass
2928 -- * Lifting other operations
3029 , liftCallCC
31− , liftListen
32− , liftPass
3330 ) where
3431
3532#if __GLASGOW_HASKELL__ < 710
@@ -46,15 +43,17 @@ import Control.Monad.Trans.Class (MonadTrans, lift)
4643import Control.Monad.IO.Class (MonadIO)
4744import Control.Monad.Morph (MFunctor, MMonad)
4845import Control.Ether.Tagged (Taggable(..), Tagged(..))
49−import qualified Control.Ether.Util as Util
5046import GHC.Generics (Generic)
5147import qualified Control.Newtype as NT
5248
5349import qualified Control.Monad.Signatures as Sig
5450import qualified Control.Monad.Trans.Control as MC
5551import qualified Control.Monad.Trans.Writer.Lazy as Trans
56−import qualified Control.Monad.Trans.Lift.Local as Lift
57−import qualified Control.Monad.Trans.Lift.Catch as Lift
52+
53+import qualified Control.Monad.Trans.Lift.Local as Lift
54+import qualified Control.Monad.Trans.Lift.Catch as Lift
55+import qualified Control.Monad.Trans.Lift.Listen as Lift
56+import qualified Control.Monad.Trans.Lift.Pass as Lift
5857
5958import qualified Control.Monad.Cont.Class as Class
6059import qualified Control.Monad.Reader.Class as Class
@@ -89,6 +88,12 @@ instance Monoid w => MC.MonadTransControl (WriterT tag w) where
8988instance Monoid w => Lift.LiftLocal (WriterT tag w)
9089instance Monoid w => Lift.LiftCatch (WriterT tag w)
9190
91+instance Monoid w' => Lift.LiftListen (WriterT tag w') where
92+ liftListen listen m = WriterT $ Lift.liftListen listen (coerce m)
93+
94+instance Monoid w' => Lift.LiftPass (WriterT tag w') where
95+ liftPass pass m = WriterT $ Lift.liftPass pass (coerce m)
96+
9297instance Taggable (WriterT tag w m) where
9398 type Tag (WriterT tag w m) = 'Just tag
9499 type Inner (WriterT tag w m) = 'Just m
@@ -127,9 +132,6 @@ execWriter t = Trans.execWriter . untagged t
127132
128133-- | Transform the computation inside a 'WriterT'.
129134--
130−-- * @'runWriterT' tag ('mapWriterT' tag f m) = f ('runWriterT' tag m)@
131−mapWriterT :: proxy tag -> (m (a, w) -> n (b, w')) -> WriterT tag w m a -> WriterT tag w' n b
132−mapWriterT t f m = tagged t $ Trans.mapWriterT f (coerce m)
133135
134136-- | Appends a value to the accumulator within the monad.
135137tell :: Monad m => proxy tag -> w -> WriterT tag w m ()
@@ -148,20 +150,12 @@ pass t m = tagged t $ Trans.pass (coerce m)
148150liftCallCC :: Monoid w => proxy tag -> Sig.CallCC m (a, w) (b, w) -> Sig.CallCC (WriterT tag w m) a b
149151liftCallCC t callCC f = tagged t $ Trans.liftCallCC callCC (coerce f)
150152
151−-- | Lift a @listen@ operation to the new monad.
152−liftListen :: Monad m => proxy tag -> Sig.Listen w' m (a, w) -> Sig.Listen w' (WriterT tag w m) a
153−liftListen t f m = tagged t $ Util.liftListen_WriterT f (coerce m)
154−
155−-- | Lift a @pass@ operation to the new monad.
156−liftPass :: Monad m => proxy tag -> Sig.Pass w' m (a, w) -> Sig.Pass w' (WriterT tag w m) a
157−liftPass t f m = tagged t $ Util.liftPass_WriterT f (coerce m)
158−
159153instance (Monoid w, Class.MonadCont m) => Class.MonadCont (WriterT tag w m) where
160154 callCC = liftCallCC Proxy Class.callCC
161155
162156instance (Monoid w, Class.MonadReader r m) => Class.MonadReader r (WriterT tag w m) where
163157 ask = lift Class.ask
164− local = mapWriterT Proxy . Class.local
158+ local = Lift.liftLocal Class.ask Class.local
165159 reader = lift . Class.reader
166160
167161instance (Monoid w, Class.MonadState s m) => Class.MonadState s (WriterT tag w m) where
@@ -172,8 +166,8 @@ instance (Monoid w, Class.MonadState s m) => Class.MonadState s (WriterT tag w m
172166instance (Monoid w, Class.MonadWriter w' m) => Class.MonadWriter w' (WriterT tag w m) where
173167 writer = lift . Class.writer
174168 tell = lift . Class.tell
175− listen = liftListen Proxy Class.listen
176− pass = liftPass Proxy Class.pass
169+ listen = Lift.liftListen Class.listen
170+ pass = Lift.liftPass Class.pass
177171
178172instance (Monoid w, Class.MonadError e m) => Class.MonadError e (WriterT tag w m) where
179173 throwError = lift . Class.throwError