@@ -26,6 +26,9 @@ module Control.Monad.Trans.Ether.Writer
2626 , tell
2727 , listen
2828 , pass
29+ -- * Newtype operations
30+ , pack
31+ , unpack
2932 ) where
3033
3134#if __GLASGOW_HASKELL__ < 710
@@ -41,7 +44,7 @@ import Control.Monad.IO.Class (MonadIO)
4144import Control.Monad.Morph (MFunctor, MMonad)
4245import Control.Ether.Tagged (Taggable(..), Tagged(..))
4346import GHC.Generics (Generic)
44−import qualified Control.Newtype as NT
47+import Data.Coerce (coerce)
4548
4649import qualified Control.Monad.Base as MB
4750import qualified Control.Monad.Trans.Control as MC
@@ -77,15 +80,21 @@ newtype WriterT tag w m a = WriterT (Trans.WriterT w m a)
7780 , Functor, Applicative, Alternative, Monad, MonadPlus
7881 , MonadFix, MonadTrans, MonadIO, MFunctor, MMonad )
7982
80−instance NT.Newtype (WriterT tag w m a)
83+-- | Type-restricted `coerce`.
84+pack :: Trans.WriterT w m a -> WriterT tag w m a
85+pack = coerce
86+
87+-- | Type-restricted `coerce`.
88+unpack :: WriterT tag w m a -> Trans.WriterT w m a
89+unpack = coerce
8190
8291instance (Monoid w, MB.MonadBase b m) => MB.MonadBase b (WriterT tag w m) where
8392 liftBase = MB.liftBaseDefault
8493
8594instance Monoid w => MC.MonadTransControl (WriterT tag w) where
8695 type StT (WriterT tag w) a = MC.StT (Trans.WriterT w) a
87− liftWith = MC.defaultLiftWith NT.pack NT.unpack
88− restoreT = MC.defaultRestoreT NT.pack
96+ liftWith = MC.defaultLiftWith pack unpack
97+ restoreT = MC.defaultRestoreT pack
8998
9099instance (Monoid w, MC.MonadBaseControl b m) => MC.MonadBaseControl b (WriterT tag w m) where
91100 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
95104type instance Lift.StT (WriterT tag w) a = MC.StT (WriterT tag w) a
96105
97106instance Monoid w => Lift.LiftLocal (WriterT tag w) where
98− liftLocal = Lift.defaultLiftLocal NT.pack NT.unpack
107+ liftLocal = Lift.defaultLiftLocal pack unpack
99108
100109instance Monoid w => Lift.LiftCatch (WriterT tag w) where
101− liftCatch = Lift.defaultLiftCatch NT.pack NT.unpack
110+ liftCatch = Lift.defaultLiftCatch pack unpack
102111
103112instance Monoid w => Lift.LiftListen (WriterT tag w) where
104− liftListen = Lift.defaultLiftListen NT.pack NT.unpack
113+ liftListen = Lift.defaultLiftListen pack unpack
105114
106115instance Monoid w' => Lift.LiftPass (WriterT tag w') where
107− liftPass = Lift.defaultLiftPass NT.pack NT.unpack
116+ liftPass = Lift.defaultLiftPass pack unpack
108117
109118instance Monoid w => Lift.LiftCallCC (WriterT tag w) where
110− liftCallCC = Lift.defaultLiftCallCC NT.pack NT.unpack
111− liftCallCC' = Lift.defaultLiftCallCC NT.pack NT.unpack
119+ liftCallCC = Lift.defaultLiftCallCC pack unpack
120+ liftCallCC' = Lift.defaultLiftCallCC pack unpack
112121
113122instance Taggable (WriterT tag w m) where
114123 type Tag (WriterT tag w m) = 'Just tag
@@ -116,6 +125,8 @@ instance Taggable (WriterT tag w m) where
116125
117126instance Tagged (WriterT tag w m) tag where
118127 type Untagged (WriterT tag w m) = Trans.WriterT w m
128+ tagged _ = pack
129+ untagged _ = unpack
119130
120131-- | Constructor for computations in the writer monad transformer.
121132writerT :: proxy tag -> m (a, w) -> WriterT tag w m a