拼写错误的标识符或缺失的导入,可能会变成意外的隐式参数,如下例所示:
inductive Answer where
| yes
| maybe
| no
def select (choices : α × α × α) : Asnwer → α
| Invalid dotted identifier notation: The expected type of `.yes`
Asnwer
is not of the form `C ...` or `... → C ...` where C is a constant.yes => choices.1
| .maybe => choices.2.1
| .no => choices.2.2
报错信息指出参数的类型不是常量,因此不能在模式中使用点记法:
Invalid dotted identifier notation: The expected type of `.yes`
Asnwer
is not of the form `C ...` or `... → C ...` where C is a constant
原因是其签名为:
select.{u_1, u_2}
{α : Type u_1}
{Asnwer : Sort u_2}
(choices : α × α × α) :
Asnwer → α
禁用“宽松”的自动隐式参数后,错误更清晰,同时仍允许自动插入类型:
set_option relaxedAutoImplicit false
def select (choices : α × α × α) : Unknown identifier `Asnwer`
Note: It is not possible to treat `Asnwer` as an implicitly bound variable here because it has multiple characters while the `relaxedAutoImplicit` option is set to `false`.Asnwer → α
| .yes => choices.1
| .maybe => choices.2.1
| .no => choices.2.2
Unknown identifier `Asnwer`
Note: It is not possible to treat `Asnwer` as an implicitly bound variable here because it has multiple characters while the `relaxedAutoImplicit` option is set to `false`.
修正该错误后,定义即可通过:
set_option relaxedAutoImplicit false
def select (choices : α × α × α) : Answer → α
| .yes => choices.1
| .maybe => choices.2.1
| .no => choices.2.2
完全关闭自动隐式参数会导致该定义被拒绝:
set_option autoImplicit false
def select (choices : Unknown identifier `α`
Note: It is not possible to treat `α` as an implicitly bound variable here because the `autoImplicit` option is set to `false`.α × Unknown identifier `α`
Note: It is not possible to treat `α` as an implicitly bound variable here because the `autoImplicit` option is set to `false`.α × Unknown identifier `α`
Note: It is not possible to treat `α` as an implicitly bound variable here because the `autoImplicit` option is set to `false`.α) : Answer → Unknown identifier `α`
Note: It is not possible to treat `α` as an implicitly bound variable here because the `autoImplicit` option is set to `false`.α
| .yes => choices.1
| .maybe => choices.2.1
| .no => choices.2.2
Unknown identifier `α`
Note: It is not possible to treat `α` as an implicitly bound variable here because the `autoImplicit` option is set to `false`.