Coq 归纳类型中多态性的不同处理方法
在定义归纳类型时,将事物放在冒号之前或之后有根本区别吗?在我看来,这主要是一个句法方便的问题。例如,这4个多态列表定义对我来说基本上是一样的:Coq 归纳类型中多态性的不同处理方法,coq,Coq,在定义归纳类型时,将事物放在冒号之前或之后有根本区别吗?在我看来,这主要是一个句法方便的问题。例如,这4个多态列表定义对我来说基本上是一样的: Inductive list1 : Type -> Type := | Nil1 : forall (X : Type), list1 X | Cons1 : forall (X : Type), X -> list1 X -> list1 X. Inductive list2 (X : Type) : Type := |
Inductive list1 : Type -> Type :=
| Nil1 : forall (X : Type), list1 X
| Cons1 : forall (X : Type), X -> list1 X -> list1 X.
Inductive list2 (X : Type) : Type :=
| Nil2 : list2 X
| Cons2 : X -> list2 X -> list2 X.
Inductive list3 {X : Type} : Type :=
| Nil3 : list3
| Cons3 : X -> list3 -> list3.
Inductive list4 : Type -> Type :=
| Nil4 : forall {X : Type}, list4 X
| Cons4 : forall {X : Type}, X -> list4 X -> list4 X.
唯一的区别是,其中一些要求更明确地说明X:Type
,如以下示例所示:
Compute Cons1 nat 3 (Nil1 nat).
Compute Cons2 nat 3 (Nil2 nat).
Compute Cons3 3 Nil3.
Compute Cons4 3 Nil4.
但是,这可以通过隐式参数
轻松解决:
Implicit Arguments Nil1 [X].
Implicit Arguments Cons1 [X].
Compute Cons1 3 Nil1.
Implicit Arguments Nil2 [X].
Implicit Arguments Cons2 [X].
Compute Cons2 3 Nil2.
因此,在我看来,这4个定义除了语法上的便利性之外,没有根本的区别。对吗?是否存在在冒号之前或之后放置某些内容会产生更显著的后果的用例?在
:
左侧的参数称为参数,在:
右侧的参数称为索引。对imo的核对答案清楚地解释了这些答案之间的区别。