@@ -26,6 +26,9 @@ module Control.Monad.Trans.Ether.Writer
29+ -- * Newtype operations
31#if __GLASGOW_HASKELL__ < 710
34#if __GLASGOW_HASKELL__ < 710
@@ -41,7 +44,7 @@ import Control.Monad.IO.Class (MonadIO)
41import Control.Monad.Morph (MFunctor, MMonad)
44import Control.Monad.Morph (MFunctor, MMonad)
42import Control.Ether.Tagged (Taggable(..), Tagged(..))
45import Control.Ether.Tagged (Taggable(..), Tagged(..))
43import GHC.Generics (Generic)
46import GHC.Generics (Generic)
44−import qualified Control.Newtype as NT
47+import Data.Coerce (coerce)
46import qualified Control.Monad.Base as MB
49import qualified Control.Monad.Base as MB
47import qualified Control.Monad.Trans.Control as MC
50import qualified Control.Monad.Trans.Control as MC
@@ -77,15 +80,21 @@ newtype WriterT tag w m a = WriterT (Trans.WriterT w m a)
77 , Functor, Applicative, Alternative, Monad, MonadPlus
80 , Functor, Applicative, Alternative, Monad, MonadPlus
78 , MonadFix, MonadTrans, MonadIO, MFunctor, MMonad )
81 , MonadFix, MonadTrans, MonadIO, MFunctor, MMonad )
83+-- | Type-restricted `coerce`.
80−instance NT.Newtype (WriterT tag w m a)
84+pack :: Trans.WriterT w m a -> WriterT tag w m a
87+-- | Type-restricted `coerce`.
88+unpack :: WriterT tag w m a -> Trans.WriterT w m a
82instance (Monoid w, MB.MonadBase b m) => MB.MonadBase b (WriterT tag w m) where
91instance (Monoid w, MB.MonadBase b m) => MB.MonadBase b (WriterT tag w m) where
83 liftBase = MB.liftBaseDefault
92 liftBase = MB.liftBaseDefault
85instance Monoid w => MC.MonadTransControl (WriterT tag w) where
94instance Monoid w => MC.MonadTransControl (WriterT tag w) where
86 type StT (WriterT tag w) a = MC.StT (Trans.WriterT w) a
95 type StT (WriterT tag w) a = MC.StT (Trans.WriterT w) a
87− liftWith = MC.defaultLiftWith NT.pack NT.unpack
96+ liftWith = MC.defaultLiftWith pack unpack
88− restoreT = MC.defaultRestoreT NT.pack
97+ restoreT = MC.defaultRestoreT pack
90instance (Monoid w, MC.MonadBaseControl b m) => MC.MonadBaseControl b (WriterT tag w m) where
99instance (Monoid w, MC.MonadBaseControl b m) => MC.MonadBaseControl b (WriterT tag w m) where
91 type StM (WriterT tag w m) a = MC.ComposeSt (WriterT tag w) m a
100 type StM (WriterT tag w m) a = MC.ComposeSt (WriterT tag w) m a
@@ -95,20 +104,20 @@ instance (Monoid w, MC.MonadBaseControl b m) => MC.MonadBaseControl b (WriterT t
95type instance Lift.StT (WriterT tag w) a = MC.StT (WriterT tag w) a
104type instance Lift.StT (WriterT tag w) a = MC.StT (WriterT tag w) a
97instance Monoid w => Lift.LiftLocal (WriterT tag w) where
106instance Monoid w => Lift.LiftLocal (WriterT tag w) where
98− liftLocal = Lift.defaultLiftLocal NT.pack NT.unpack
107+ liftLocal = Lift.defaultLiftLocal pack unpack
100instance Monoid w => Lift.LiftCatch (WriterT tag w) where
109instance Monoid w => Lift.LiftCatch (WriterT tag w) where
101− liftCatch = Lift.defaultLiftCatch NT.pack NT.unpack
110+ liftCatch = Lift.defaultLiftCatch pack unpack
103instance Monoid w => Lift.LiftListen (WriterT tag w) where
112instance Monoid w => Lift.LiftListen (WriterT tag w) where
104− liftListen = Lift.defaultLiftListen NT.pack NT.unpack
113+ liftListen = Lift.defaultLiftListen pack unpack
106instance Monoid w' => Lift.LiftPass (WriterT tag w') where
115instance Monoid w' => Lift.LiftPass (WriterT tag w') where
107− liftPass = Lift.defaultLiftPass NT.pack NT.unpack
116+ liftPass = Lift.defaultLiftPass pack unpack
109instance Monoid w => Lift.LiftCallCC (WriterT tag w) where
118instance Monoid w => Lift.LiftCallCC (WriterT tag w) where
110− liftCallCC = Lift.defaultLiftCallCC NT.pack NT.unpack
119+ liftCallCC = Lift.defaultLiftCallCC pack unpack
111− liftCallCC' = Lift.defaultLiftCallCC NT.pack NT.unpack
120+ liftCallCC' = Lift.defaultLiftCallCC pack unpack
113instance Taggable (WriterT tag w m) where
122instance Taggable (WriterT tag w m) where
114 type Tag (WriterT tag w m) = 'Just tag
123 type Tag (WriterT tag w m) = 'Just tag
@@ -116,6 +125,8 @@ instance Taggable (WriterT tag w m) where
117instance Tagged (WriterT tag w m) tag where
126instance Tagged (WriterT tag w m) tag where
118 type Untagged (WriterT tag w m) = Trans.WriterT w m
127 type Untagged (WriterT tag w m) = Trans.WriterT w m
120-- | Constructor for computations in the writer monad transformer.
131-- | Constructor for computations in the writer monad transformer.
121writerT :: proxy tag -> m (a, w) -> WriterT tag w m a
132writerT :: proxy tag -> m (a, w) -> WriterT tag w m a