【发布时间】:2014-11-24 16:18:00
【问题描述】:
我不明白为什么这个程序不能打字:
type Test a = forall z. (a -> z) -> z
cons :: a -> Test a
cons = \a -> \p -> p a
type Identity = forall x. x -> x
t :: Identity
t = \x -> x
c :: Test Identity
c = cons (t :: Identity)
main :: IO ()
main = do{
print "test"
}
我在 GHC 中使用选项 -XRankNTypes。
我有以下错误:
Couldn't match type `x0 -> x0' with `forall x. x -> x'
Expected type: Identity
Actual type: x0 -> x0
In the first argument of `cons', namely `(t :: Identity)'
In the expression: cons (t :: Identity)
In an equation for `c': c = cons (t :: Identity)
有人可以帮我吗?
【问题讨论】:
标签: haskell polymorphism type-inference system-f