@@ -32,7 +32,6 @@ import Data.Monoid
34import Data.Functor.Identity (Identity(..))
34import Data.Functor.Identity (Identity(..))
35−import Data.Coerce (coerce)
36import Control.Applicative
35import Control.Applicative
37import Control.Monad (MonadPlus)
36import Control.Monad (MonadPlus)
38import Control.Monad.Fix (MonadFix)
37import Control.Monad.Fix (MonadFix)
@@ -70,7 +69,7 @@ type Writer tag w = WriterT tag w Identity
71-- The 'return' function produces the output 'mempty', while '>>=' combines
70-- The 'return' function produces the output 'mempty', while '>>=' combines
72-- the outputs of the subcomputations using 'mappend'.
71-- 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 }
74 deriving ( Generic
73 deriving ( Generic
75 , Functor, Applicative, Alternative, Monad, MonadPlus
74 , Functor, Applicative, Alternative, Monad, MonadPlus
76 , MonadFix, MonadTrans, MonadIO, MFunctor, MMonad )
75 , MonadFix, MonadTrans, MonadIO, MFunctor, MMonad )
@@ -79,20 +78,18 @@ instance NT.Newtype (WriterT tag w m a)
80instance Monoid w => MC.MonadTransControl (WriterT tag w) where
79instance Monoid w => MC.MonadTransControl (WriterT tag w) where
81 type StT (WriterT tag w) a = MC.StT (Trans.WriterT w) a
80 type StT (WriterT tag w) a = MC.StT (Trans.WriterT w) a
82− liftWith f = WriterT $ MC.liftWith (f . coerce)
81+ liftWith = MC.defaultLiftWith WT runWT
83− restoreT = WriterT . MC.restoreT
82+ restoreT = MC.defaultRestoreT WT
85−instance Monoid w => Lift.LiftLocal (WriterT tag w)
84+instance Monoid w => Lift.LiftLocal (WriterT tag w)
86−instance Monoid w => Lift.LiftCatch (WriterT tag w)
85+instance Monoid w => Lift.LiftCatch (WriterT tag w)
88−instance Monoid w' => Lift.LiftListen (WriterT tag w') where
86+instance Monoid w => Lift.LiftListen (WriterT tag w)
89− liftListen listen' m = WriterT $ Lift.liftListen listen' (coerce m)
91instance Monoid w' => Lift.LiftPass (WriterT tag w') where
88instance 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)
94instance Monoid w => Lift.LiftCallCC (WriterT tag w) where
91instance 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))
97instance Taggable (WriterT tag w m) where
94instance Taggable (WriterT tag w m) where
98 type Tag (WriterT tag w m) = 'Just tag
95 type Tag (WriterT tag w m) = 'Just tag
@@ -136,12 +133,12 @@ tell t w = writer t ((), w)
137-- | Executes an action and adds its accumulator to the value of the computation.
134-- | Executes an action and adds its accumulator to the value of the computation.
138listen :: (Monoid w, Monad m) => proxy tag -> WriterT tag w m a -> WriterT tag w m (a, w)
135listen :: (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)
141-- | Executes an action which returns a value and a function, and returns the
138-- | Executes an action which returns a value and a function, and returns the
142-- value, applying the function to the accumulator.
139-- value, applying the function to the accumulator.
143pass :: (Monoid w, Monad m) => proxy tag -> WriterT tag w m (a, w -> w) -> WriterT tag w m a
140pass :: (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)
146instance (Monoid w, Class.MonadCont m) => Class.MonadCont (WriterT tag w m) where
143instance (Monoid w, Class.MonadCont m) => Class.MonadCont (WriterT tag w m) where
147 callCC = Lift.liftCallCC Class.callCC
144 callCC = Lift.liftCallCC Class.callCC