在‘Practical type inference for arbitrary-rank types’一文中,作者谈到了包容性(subsumption):
我在阅读时尝试在GHCi中测试事物,但即使g k2
应该可以通过类型检查,在我使用GHC 7.8.3时却不能:
λ> :set -XRankNTypes
λ> let g :: ((forall b. [b] -> [b]) -> Int) -> Int; g = undefined
λ> let k1 :: (forall a. a -> a) -> Int; k1 = undefined
λ> let k2 :: ([Int] -> [Int]) -> Int; k2 = undefined
λ> :t g k1
<interactive>:1:3: Warning:
Couldn't match type ‘a’ with ‘[a]’
‘a’ is a rigid type variable bound by
the type forall a1. a1 -> a1 at <interactive>:1:3
Expected type: (forall b. [b] -> [b]) -> Int
Actual type: (forall a. a -> a) -> Int
In the first argument of ‘g’, namely ‘k1’
In the expression: g k1
g k1 :: Int
λ> :t g k2
<interactive>:1:3: Warning:
Couldn't match type ‘[Int] -> [Int]’ with ‘forall b. [b] -> [b]’
Expected type: (forall b. [b] -> [b]) -> Int
Actual type: ([Int] -> [Int]) -> Int
In the first argument of ‘g’, namely ‘k2’
In the expression: g k2
g k2 :: Int
我还没有真正理解这篇论文,但我担心自己可能误解了一些内容。这个类型检查是否正确?我的Haskell类型是否有误?
g k2
而没有投诉。(请参见此处的示例:https://github.com/Frege/frege/issues/80#issuecomment-62257574) - Ingo