为什么 Agda 报错 "expected: ℕ, actual: ℕ"
Why does Agda give error "expected: ℕ, actual: ℕ"
当我写下面的函数是agda时,
f : (A : Set) → (a : A) → ℕ
f ℕ n = n
我预计错误会说我没有指定所有情况。
相反,我收到此错误:
Type mismatch:
expected: ℕ
actual: ℕ
when checking that the expression n
has type ℕ
这是怎么回事?
使用更新版本的 Agda(我使用的是 2.5.4)你会得到一个信息更丰富的错误:
ℕ !=< ℕ of type Set
(because one is a variable and one a defined identifier)
when checking that the expression n has type ℕ
问题在于函数定义的模式(等号左侧)只能包含构造函数、变量和点模式,而不能包含 ℕ
等类型。由于 ℕ
不是一个有效的模式,Agda 假设(可能令人困惑)它是一个名为 ℕ
的新变量,类型为 Set
,因此隐藏了自然的实际类型 ℕ
数字。现在错误是有道理的,因为 n
的类型(即 ℕ
变量)不等于预期的 return 类型(即自然的 ℕ
类型数字)。
当我写下面的函数是agda时,
f : (A : Set) → (a : A) → ℕ
f ℕ n = n
我预计错误会说我没有指定所有情况。
相反,我收到此错误:
Type mismatch:
expected: ℕ
actual: ℕ
when checking that the expression n
has type ℕ
这是怎么回事?
使用更新版本的 Agda(我使用的是 2.5.4)你会得到一个信息更丰富的错误:
ℕ !=< ℕ of type Set
(because one is a variable and one a defined identifier)
when checking that the expression n has type ℕ
问题在于函数定义的模式(等号左侧)只能包含构造函数、变量和点模式,而不能包含 ℕ
等类型。由于 ℕ
不是一个有效的模式,Agda 假设(可能令人困惑)它是一个名为 ℕ
的新变量,类型为 Set
,因此隐藏了自然的实际类型 ℕ
数字。现在错误是有道理的,因为 n
的类型(即 ℕ
变量)不等于预期的 return 类型(即自然的 ℕ
类型数字)。