有了量化的约束,我可以Eq (A f)
很好地推导出来吗?但是,当我尝试导出 Ord (A f) 时,它失败了。当约束类具有超类时,我不明白如何使用量化约束。如何派生Ord (A f)
和其他具有超类的类?
> newtype A f = A (f Int)
> deriving instance (forall a. Eq a => Eq (f a)) => Eq (A f)
> deriving instance (forall a. Ord a => Ord (f a)) => Ord (A f)
<interactive>:3:1: error:
• Could not deduce (Ord a)
arising from the superclasses of an instance declaration
from the context: forall a. Ord a => Ord (f a)
bound by the instance declaration at <interactive>:3:1-61
or from: Eq a bound by a quantified context at <interactive>:1:1
Possible fix: add (Ord a) to the context of a quantified context
• In the instance declaration for 'Ord (A f)'
PS。我还检查了ghc 提案 0109-quantified-constraints。使用 ghc 8.6.5