on master help sign in
Use CPS-d WriterT
a33c33aVladislav Zavialov
ether.cabal+3−2
@@ -38,12 +38,13 @@ library
38
38
39 build-depends:
39 build-depends:
40 base >=4.9 && <4.11,
40 base >=4.9 && <4.11,
41− transformers >=0.4.2,
41+ transformers >=0.5.4.0,
42− transformers-lift >=0.1.0.1,
42+ transformers-lift >=0.2.0.0,
43 mtl >=2.2.1,
43 mtl >=2.2.1,
44 mmorph >=1.0.4,
44 mmorph >=1.0.4,
45 monad-control >=1.0.0.4,
45 monad-control >=1.0.0.4,
46 transformers-base >=0.4.4,
46 transformers-base >=0.4.4,
47+ writer-cps-mtl >= 0.1.1.4,
47 exceptions >=0.8,
48 exceptions >=0.8,
48 template-haskell >=2.11,
49 template-haskell >=2.11,
49 tagged >=0.8.5,
50 tagged >=0.8.5,
src/Ether/Writer.hs+19−18
@@ -42,7 +42,8 @@ module Ether.Writer
42import Control.Monad.Signatures (Listen, Pass)
42import Control.Monad.Signatures (Listen, Pass)
43import qualified Control.Monad.Trans.Lift.Listen as Lift
43import qualified Control.Monad.Trans.Lift.Listen as Lift
44import qualified Control.Monad.Trans.Lift.Pass as Lift
44import qualified Control.Monad.Trans.Lift.Pass as Lift
45−import qualified Control.Monad.Writer as T
45+import qualified Control.Monad.Writer.Class as T
46+import qualified Control.Monad.Writer.CPS as T.CPS
46import Data.Coerce
47import Data.Coerce
47import Data.Functor.Identity
48import Data.Functor.Identity
48
49
@@ -117,37 +118,37 @@ type Writer tag w = WriterT tag w Identity
117--
118--
118-- The 'return' function produces the output 'mempty', while '>>=' combines
119-- The 'return' function produces the output 'mempty', while '>>=' combines
119-- the outputs of the subcomputations using 'mappend'.
120-- the outputs of the subcomputations using 'mappend'.
120−type WriterT tag w = TaggedTrans (TAGGED WRITER tag) (T.WriterT w)
121+type WriterT tag w = TaggedTrans (TAGGED WRITER tag) (T.CPS.WriterT w)
121
122
122-- | Constructor for computations in the writer monad transformer.
123-- | Constructor for computations in the writer monad transformer.
123−writerT :: forall tag w m a . m (a, w) -> WriterT tag w m a
124+writerT :: forall tag w m a . (Functor m, Monoid w) => m (a, w) -> WriterT tag w m a
124−writerT = coerce (T.WriterT @w @m @a)
125+writerT = coerce (T.CPS.writerT @m @w @a)
125
126
126-- | Runs a 'WriterT' and returns both the normal value
127-- | Runs a 'WriterT' and returns both the normal value
127-- and the final accumulator.
128-- and the final accumulator.
128−runWriterT :: forall tag w m a . WriterT tag w m a -> m (a, w)
129+runWriterT :: forall tag w m a . Monoid w => WriterT tag w m a -> m (a, w)
129−runWriterT = coerce (T.runWriterT @w @m @a)
130+runWriterT = coerce (T.CPS.runWriterT @w @m @a)
130
131
131-- | Runs a 'Writer' and returns both the normal value
132-- | Runs a 'Writer' and returns both the normal value
132-- and the final accumulator.
133-- and the final accumulator.
133−runWriter :: forall tag w a . Writer tag w a -> (a, w)
134+runWriter :: forall tag w a . Monoid w => Writer tag w a -> (a, w)
134−runWriter = coerce (T.runWriter @w @a)
135+runWriter = coerce (T.CPS.runWriter @w @a)
135
136
136-- | Runs a 'WriterT' and returns the final accumulator,
137-- | Runs a 'WriterT' and returns the final accumulator,
137-- discarding the normal value.
138-- discarding the normal value.
138−execWriterT :: forall tag w m a . Monad m => WriterT tag w m a -> m w
139+execWriterT :: forall tag w m a . (Monad m, Monoid w) => WriterT tag w m a -> m w
139−execWriterT = coerce (T.execWriterT @m @w @a)
140+execWriterT = coerce (T.CPS.execWriterT @m @w @a)
140
141
141-- | Runs a 'Writer' and returns the final accumulator,
142-- | Runs a 'Writer' and returns the final accumulator,
142-- discarding the normal value.
143-- discarding the normal value.
143−execWriter :: forall tag w a . Writer tag w a -> w
144+execWriter :: forall tag w a . Monoid w => Writer tag w a -> w
144−execWriter = coerce (T.execWriter @w @a)
145+execWriter = coerce (T.CPS.execWriter @w @a)
145
146
146type instance HandleSuper WRITER w trans = Monoid w
147type instance HandleSuper WRITER w trans = Monoid w
147type instance HandleConstraint WRITER w trans m =
148type instance HandleConstraint WRITER w trans m =
148 T.MonadWriter w (trans m)
149 T.MonadWriter w (trans m)
149
150
150−instance Monoid w => Handle WRITER w (T.WriterT w) where
151+instance Monoid w => Handle WRITER w (T.CPS.WriterT w) where
151 handling r = r
152 handling r = r
152 {-# INLINE handling #-}
153 {-# INLINE handling #-}
153
154
@@ -182,21 +183,21 @@ instance
182
183
183type Writer' w = Writer w w
184type Writer' w = Writer w w
184
185
185−runWriter' :: Writer' w a -> (a, w)
186+runWriter' :: Monoid w => Writer' w a -> (a, w)
186runWriter' = runWriter
187runWriter' = runWriter
187
188
188−execWriter' :: Writer' w a -> w
189+execWriter' :: Monoid w => Writer' w a -> w
189execWriter' = execWriter
190execWriter' = execWriter
190
191
191type WriterT' w = WriterT w w
192type WriterT' w = WriterT w w
192
193
193−writerT' :: m (a, w) -> WriterT' w m a
194+writerT' :: (Functor m, Monoid w) => m (a, w) -> WriterT' w m a
194writerT' = writerT
195writerT' = writerT
195
196
196−runWriterT' :: WriterT' w m a -> m (a, w)
197+runWriterT' :: Monoid w => WriterT' w m a -> m (a, w)
197runWriterT' = runWriterT
198runWriterT' = runWriterT
198
199
199−execWriterT' :: Monad m => WriterT' w m a -> m w
200+execWriterT' :: (Monad m, Monoid w) => WriterT' w m a -> m w
200execWriterT' = execWriterT
201execWriterT' = execWriterT
201
202
202type MonadWriter' w = MonadWriter w w
203type MonadWriter' w = MonadWriter w w
stack.yaml+6
@@ -1,2 +1,8 @@
1resolver: lts-8.12
1resolver: lts-8.12
2packages: ['.']
2packages: ['.']
3+
4+extra-deps:
5+- transformers-0.5.4.0
6+- transformers-lift-0.2.0.0
7+- writer-cps-transformers-0.1.1.3
8+- writer-cps-mtl-0.1.1.4