类型作为 coq 中的参数

types as parameters in coq

我在 stackexchange post 上找到了这段代码,但我对它的工作原理感到困惑。特别是,

Inductive Vector {A : Type} : nat -> Type :=
| nil : Vector 0
  | cons : forall n, A -> Vector n -> Vector (S n).

(* This works. *)
Check (let n := 0 in cons n 42 nil).

在检查中,42是否绑定到A? A 不必是类型吗?我尝试用显然是类型的东西替换 42,例如 'bool' 或 'Type',这些也有效。这对我来说很有意义。但是 42 如何在那里进行类型检查?

AVectorimplicit argument,它(默认情况下)由构造函数 cons 继承。这由 Inductive Vector {A : Type} : nat -> TypeA : Type 周围的大括号表示。

因此,在cons n 42 nil中,cons应用于某些隐式类型?A、自然数n?A类型的元素42Vector 0 nil。由于 42 的类型为 nat,因此 ?A 可以推断为 nat.