If statement 在Coq中,“在;如果是,则为“否则”;允许非布尔第一个参数?

If statement 在Coq中,“在;如果是,则为“否则”;允许非布尔第一个参数?,if-statement,types,coq,If Statement,Types,Coq,我在一些教程中读到,if a then b else c代表match a with true=>b | false=>c end。然而,很奇怪,前者没有检查a的类型,而后者当然确保a是一个布尔值。比如说, Coq < Check if nil then 1 else 2. if nil then 1 else 2 : nat where ?A : [ |- Type] Coq < Check match nil with true => 1 | false =

我在一些教程中读到,
if a then b else c
代表
match a with true=>b | false=>c end
。然而,很奇怪,前者没有检查
a
的类型,而后者当然确保
a
是一个布尔值。比如说,

Coq < Check if nil then 1 else 2.
if nil then 1 else 2
     : nat
where
?A : [ |- Type] 


Coq < Check match nil with true => 1 | false => 2 end.
Toplevel input, characters 33-38:
> Check match nil with true => 1 | false => 2 end.
>                                  ^^^^^
Error: Found a constructor of inductive type bool while
a constructor of list is expected.
Coq<检查是否为零,然后是1或2。
如果为零,则为1,否则为2
:纳特
哪里
?A:[|-类型]
Coq<检查匹配nil的true=>1 | false=>2结束。
顶级输入,字符33-38:
>选择匹配nil,true=>1 | false=>2结束。
>                                  ^^^^^
错误:发现归纳类型bool的构造函数时
应为list的构造函数。
如果。。。然后。。。else…是否允许其第一个参数不是非布尔值?有超载的情况吗?(
查找“if”。
没有给出结果。)

让我引用以下内容:

对于只有两个构造函数的归纳类型和不依赖于构造函数参数的模式匹配表达式,如果。。。然后。。。否则…表示法。更一般地说,对于构造函数为
C1
C2
的归纳类型,我们具有以下等价性:

if term [dep_ret_type] then term1 else term2 
相当于

match term [dep_ret_type] with
| C1 _ ... _ => term1              (* we cannot bind the arguments *)
| C2 _ ... _ => term2
end
如您所见,第一个构造函数被视为
true
value。以下是一个例子:

Definition is_empty {A : Type} (xs : list A) : bool :=
  if xs then true else false.