@@ -21,15 +21,12 @@ module Control.Monad.Trans.Ether.Writer
22 , runWriterT
22 , runWriterT
23 , execWriterT
23 , execWriterT
25 -- * Writer operations
24 -- * Writer operations
29 -- * Lifting other operations
28 -- * Lifting other operations
30 , liftCallCC
29 , liftCallCC
35#if __GLASGOW_HASKELL__ < 710
32#if __GLASGOW_HASKELL__ < 710
@@ -46,15 +43,17 @@ import Control.Monad.Trans.Class (MonadTrans, lift)
46import Control.Monad.IO.Class (MonadIO)
43import Control.Monad.IO.Class (MonadIO)
47import Control.Monad.Morph (MFunctor, MMonad)
44import Control.Monad.Morph (MFunctor, MMonad)
48import Control.Ether.Tagged (Taggable(..), Tagged(..))
45import Control.Ether.Tagged (Taggable(..), Tagged(..))
49−import qualified Control.Ether.Util as Util
50import GHC.Generics (Generic)
46import GHC.Generics (Generic)
51import qualified Control.Newtype as NT
47import qualified Control.Newtype as NT
53import qualified Control.Monad.Signatures as Sig
49import qualified Control.Monad.Signatures as Sig
54import qualified Control.Monad.Trans.Control as MC
50import qualified Control.Monad.Trans.Control as MC
55import qualified Control.Monad.Trans.Writer.Lazy as Trans
51import qualified Control.Monad.Trans.Writer.Lazy as Trans
56−import qualified Control.Monad.Trans.Lift.Local as Lift
53+import qualified Control.Monad.Trans.Lift.Local as Lift
57−import qualified Control.Monad.Trans.Lift.Catch 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
59import qualified Control.Monad.Cont.Class as Class
58import qualified Control.Monad.Cont.Class as Class
60import qualified Control.Monad.Reader.Class as Class
59import qualified Control.Monad.Reader.Class as Class
@@ -89,6 +88,12 @@ instance Monoid w => MC.MonadTransControl (WriterT tag w) where
89instance Monoid w => Lift.LiftLocal (WriterT tag w)
88instance Monoid w => Lift.LiftLocal (WriterT tag w)
90instance Monoid w => Lift.LiftCatch (WriterT tag w)
89instance Monoid w => Lift.LiftCatch (WriterT tag w)
91+instance Monoid w' => Lift.LiftListen (WriterT tag w') where
92+ liftListen listen m = WriterT $ Lift.liftListen listen (coerce m)
94+instance Monoid w' => Lift.LiftPass (WriterT tag w') where
95+ liftPass pass m = WriterT $ Lift.liftPass pass (coerce m)
92instance Taggable (WriterT tag w m) where
97instance Taggable (WriterT tag w m) where
93 type Tag (WriterT tag w m) = 'Just tag
98 type Tag (WriterT tag w m) = 'Just tag
94 type Inner (WriterT tag w m) = 'Just m
99 type Inner (WriterT tag w m) = 'Just m
@@ -127,9 +132,6 @@ execWriter t = Trans.execWriter . untagged t
128-- | Transform the computation inside a 'WriterT'.
133-- | Transform the computation inside a 'WriterT'.
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)
134-- | Appends a value to the accumulator within the monad.
136-- | Appends a value to the accumulator within the monad.
135tell :: Monad m => proxy tag -> w -> WriterT tag w m ()
137tell :: Monad m => proxy tag -> w -> WriterT tag w m ()
@@ -148,20 +150,12 @@ pass t m = tagged t $ Trans.pass (coerce m)
148liftCallCC :: Monoid w => proxy tag -> Sig.CallCC m (a, w) (b, w) -> Sig.CallCC (WriterT tag w m) a b
150liftCallCC :: Monoid w => proxy tag -> Sig.CallCC m (a, w) (b, w) -> Sig.CallCC (WriterT tag w m) a b
149liftCallCC t callCC f = tagged t $ Trans.liftCallCC callCC (coerce f)
151liftCallCC t callCC f = tagged t $ Trans.liftCallCC callCC (coerce f)
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)
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)
159instance (Monoid w, Class.MonadCont m) => Class.MonadCont (WriterT tag w m) where
153instance (Monoid w, Class.MonadCont m) => Class.MonadCont (WriterT tag w m) where
160 callCC = liftCallCC Proxy Class.callCC
154 callCC = liftCallCC Proxy Class.callCC
162instance (Monoid w, Class.MonadReader r m) => Class.MonadReader r (WriterT tag w m) where
156instance (Monoid w, Class.MonadReader r m) => Class.MonadReader r (WriterT tag w m) where
163 ask = lift Class.ask
157 ask = lift Class.ask
164− local = mapWriterT Proxy . Class.local
158+ local = Lift.liftLocal Class.ask Class.local
165 reader = lift . Class.reader
159 reader = lift . Class.reader
167instance (Monoid w, Class.MonadState s m) => Class.MonadState s (WriterT tag w m) where
161instance (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
172instance (Monoid w, Class.MonadWriter w' m) => Class.MonadWriter w' (WriterT tag w m) where
166instance (Monoid w, Class.MonadWriter w' m) => Class.MonadWriter w' (WriterT tag w m) where
173 writer = lift . Class.writer
167 writer = lift . Class.writer
174 tell = lift . Class.tell
168 tell = lift . Class.tell
175− listen = liftListen Proxy Class.listen
169+ listen = Lift.liftListen Class.listen
176− pass = liftPass Proxy Class.pass
170+ pass = Lift.liftPass Class.pass
178instance (Monoid w, Class.MonadError e m) => Class.MonadError e (WriterT tag w m) where
172instance (Monoid w, Class.MonadError e m) => Class.MonadError e (WriterT tag w m) where
179 throwError = lift . Class.throwError
173 throwError = lift . Class.throwError