【发布时间】:2019-03-13 10:36:15
【问题描述】:
我想知道什么 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'
【问题讨论】: