我正在尝试为 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)’
我以前遇到过 Undecidable Instances ,但我不确定为什么这是不可判定的,我该如何解决?我需要添加 UndecidableInstances 吗?谢谢!!