我正在尝试为Cofree编写以下Monoid实例:
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')
但我收到以下错误:
• 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)’
之前我遇到过不可判定的实例,但我不确定为什么这是不可判断的,我该如何解决?我需要添加UndecidableInstances吗?谢谢!