Writing generic Monoid over Cofree; undecidable?

60 views Asked by At

I'm trying to write the following Monoid instance for Cofree:

instance (Monoid a, Monoid (f (Cofree f a))) => Monoid (Cofree f a) where
  mempty = mempty :< mempty
  (a :< rest) `mappend` (b :< rest') = (a `mappend` b) :< (rest `mappend` rest')

but I'm getting the following error:

• Variable ‘f’ occurs more often
    in the constraint ‘Monoid (f (Cofree f a))’
    than in the instance head
  (Use UndecidableInstances to permit this)
• In the instance declaration for ‘Monoid (Cofree f a)’

I've come across Undecidable Instances before, but I'm not really sure WHY this is undecidable, and how can I fix it? Do I need to add UndecidableInstances? Thanks!!

0

There are 0 answers