in Haskell, I would like to make a Writer monad an instance of a monoid:
instance (Monoid a) => Monoid (Writer (Sum Int) a) where
mempty = return mempty
w1 `mappend` w2 = writer((s++t, s'++t'), Sum (m+n)) where
((s,s'), Sum m) = runWriter w1
((t,t'), Sum n) = runWriter w2
So, intuitively, if the "data" type of the Writer monad is a monoid, I want to be able to consider the whole Writer thing as a monoid as well (as implemented by mempty and mappend.
This doesn't work, though: The GHCI compiler says
Illegal instance declaration for `Monoid (Writer (Sum Int) a)'
(All instance types must be of the form (T t1 ... tn)
where T is not a synonym.
Use -XTypeSynonymInstances if you want to disable this.)
In the instance declaration for `Monoid (Writer (Sum Int) a)'
and I really don't know what type is supposed to be a synonym here and how I can conform to the compiler's rules.
-XTypeSynonymInstances
as the compiler suggests.-XFlexiblesInstances
may also be required. – user2407038