有了量化的约束,我可以得出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
deriving instance (forall a. (Eq a, Ord a) => (Eq (f a), Ord (f a))) => Ord (A f)
。你知道为什么会有区别吗?