我想知道Haskell类型声明与下面的类型方案匹配的是什么?
∀a,b.H(a→b)⇒b
这是来自4.1 Unambiguity / A Theory of Overloading
后来编辑chi的答案。我尝试了这段代码,但我不能让它失败
class H f where
g :: f -> Bool
instance H (Integer -> Bool) where
g f = f 0
instance H (Char -> Bool) where
g f = f '1'
g (\x -> if x > 10 then True else False)
g (\x -> if x == '0' then True else False)
此外,我意识到,通过添加像| b -> a
这样的函数依赖来匹配此传播规则,此代码无法使类型明确无误。
(FH) H (a —> b),H (a' —> b) => a = a'
由于H
是类型类名称,因此它可以允许多个实例
instance H (Int -> Bool) where
instance H (Char -> Bool) where
...
在这种情况下,如果我们有一个术语
x :: ∀a,b. H(a → b) ⇒ b
我们需要计算
x && True
我们需要检查x :: Bool
,但这只能确定b = Bool
,而a = Int
和a = Char
都可以使用。因此,这种类型是模棱两可的。