为什么Agda给出错误"预期:ℕ,实际:ℕ"

whi*_*ork 0 agda dependent-type

当我写下以下函数是agda时,

f : (A : Set) ? (a : A) ? ?
f ? n = n
Run Code Online (Sandbox Code Playgroud)

我希望错误说我没有指定所有情况.

相反,我收到此错误:

Type mismatch:
expected: ?
actual: ?
when checking that the expression n
has type ?
Run Code Online (Sandbox Code Playgroud)

这里发生了什么?

Jes*_*per 5

使用更新版本的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 ?
Run Code Online (Sandbox Code Playgroud)

问题是函数定义的模式(在等号的左边)可以只包含构造函数,变量和点模式,但不能包含诸如?.由于?不是一个有效的模式,Agda假定(可能容易混淆)它是一个名为?type 的新变量Set,因此遮蔽了实际?的自然数类型.现在错误是有道理的,因为n(它是?变量)的类型不等于预期的返回类型(这是?自然数的类型).