@@ -32,7 +32,6 @@ import Data.Monoid
3232#endif
3333
3434import Data.Functor.Identity (Identity(..))
35−import Data.Coerce (coerce)
3635import Control.Applicative
3736import Control.Monad (MonadPlus)
3837import Control.Monad.Fix (MonadFix)
@@ -70,7 +69,7 @@ type Writer tag w = WriterT tag w Identity
7069--
7170-- The 'return' function produces the output 'mempty', while '>>=' combines
7271-- the outputs of the subcomputations using 'mappend'.
73−newtype WriterT tag w m a = WriterT (Trans.WriterT w m a)
72+newtype WriterT tag w m a = WT { runWT :: Trans.WriterT w m a }
7473 deriving ( Generic
7574 , Functor, Applicative, Alternative, Monad, MonadPlus
7675 , MonadFix, MonadTrans, MonadIO, MFunctor, MMonad )
@@ -79,20 +78,18 @@ instance NT.Newtype (WriterT tag w m a)
7978
8079instance Monoid w => MC.MonadTransControl (WriterT tag w) where
8180 type StT (WriterT tag w) a = MC.StT (Trans.WriterT w) a
82− liftWith f = WriterT $ MC.liftWith (f . coerce)
83− restoreT = WriterT . MC.restoreT
81+ liftWith = MC.defaultLiftWith WT runWT
82+ restoreT = MC.defaultRestoreT WT
8483
85−instance Monoid w => Lift.LiftLocal (WriterT tag w)
86−instance Monoid w => Lift.LiftCatch (WriterT tag w)
87−
88−instance Monoid w' => Lift.LiftListen (WriterT tag w') where
89− liftListen listen' m = WriterT $ Lift.liftListen listen' (coerce m)
84+instance Monoid w => Lift.LiftLocal (WriterT tag w)
85+instance Monoid w => Lift.LiftCatch (WriterT tag w)
86+instance Monoid w => Lift.LiftListen (WriterT tag w)
9087
9188instance Monoid w' => Lift.LiftPass (WriterT tag w') where
92− liftPass pass' m = WriterT $ Lift.liftPass pass' (coerce m)
89+ liftPass pass' m = WT $ Lift.liftPass pass' (runWT m)
9390
9491instance Monoid w => Lift.LiftCallCC (WriterT tag w) where
95− liftCallCC callCC f = WriterT $ Lift.liftCallCC callCC (coerce f)
92+ liftCallCC callCC f = WT $ Lift.liftCallCC callCC (\g -> (runWT . f) (WT . g))
9693
9794instance Taggable (WriterT tag w m) where
9895 type Tag (WriterT tag w m) = 'Just tag
@@ -136,12 +133,12 @@ tell t w = writer t ((), w)
136133
137134-- | Executes an action and adds its accumulator to the value of the computation.
138135listen :: (Monoid w, Monad m) => proxy tag -> WriterT tag w m a -> WriterT tag w m (a, w)
139−listen t m = tagged t $ Trans.listen (coerce m)
136+listen t m = tagged t $ Trans.listen (untagged t m)
140137
141138-- | Executes an action which returns a value and a function, and returns the
142139-- value, applying the function to the accumulator.
143140pass :: (Monoid w, Monad m) => proxy tag -> WriterT tag w m (a, w -> w) -> WriterT tag w m a
144−pass t m = tagged t $ Trans.pass (coerce m)
141+pass t m = tagged t $ Trans.pass (untagged t m)
145142
146143instance (Monoid w, Class.MonadCont m) => Class.MonadCont (WriterT tag w m) where
147144 callCC = Lift.liftCallCC Class.callCC