我可以写以下内容:
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ConstraintKinds #-}
f :: Integral a => (forall b. Num b => b) -> a
f = id
一切都很好。据推测,GHC 可以从中得到Integral
一切Num
都很好。
我可能有点狡猾,但我仍然很好:
class Integral x => MyIntegral x
instance Integral x => MyIntegral x
class Num x => MyNum x
instance Num x => MyNum x
f' :: MyIntegral a => (forall b. MyNum b => b) -> a
f' = id
所以可以说我想概括一下,就像这样:
g :: c2 a => (forall b. c1 b => b) -> a
g = id
现在显然这会吐出假人,因为 GHC 不能派生c2
自c1
,因为c2
不受约束。
我需要在类型签名中添加什么g
才能说“您可以c2
从c1
”派生?