Coq 中不同类型的重载符号
Overloading notation for different types in Coq
我希望能够为不同的归纳定义定义相同的 Coq 符号,并根据参数的类型区分符号。
这是一个最小的例子:
Inductive type : Type :=
| TBool : type.
Inductive term1 : Type :=
| tvar1 : term1.
Inductive term2 : Type :=
| tvar2 : term2.
Definition context := nat -> (option type).
Reserved Notation "G '⊢' t '::' T" (at level 40, t at level 59).
Inductive typing1 : context -> term1 -> type -> Prop :=
| T_Var1 : forall G T,
G ⊢ tvar1 :: T
where "G '⊢' t1 '::' T" := (typing1 G t1 T)
with typing2 : context -> term2 -> type -> Prop :=
| T_Var2 : forall G T,
G ⊢ tvar2 :: T
where "G '⊢' t2 '::' T" := (typing2 G t2 T).
如您所见,有一个互归纳定义,其中我希望能够对不同类型的术语(term1
和 term2
)使用相同的表示法。
我在尝试编译时遇到的错误是 The term "tvar1" has type "term1" while it is expected to have type "term2".
。
有没有办法让它工作?
我写信给 Coq 邮件列表并收到来自 Gaëtan Gilbert 的 answer,它使用类型 类:
解决了我的问题
Inductive type : Type :=
| TBool : type.
Inductive term1 : Type :=
| tvar1 : term1.
Inductive term2 : Type :=
| tvar2 : term2.
Definition context := nat -> (option type).
Class VDash (A B C : Type) := vdash : A -> B -> C -> Prop.
Notation "G '⊢' t '::' T" := (vdash G t T) (at level 40, t at level 59).
Inductive typing1 : VDash context term1 type :=
| T_Var1 : forall G T,
G ⊢ tvar1 :: T
with typing2 : VDash context term2 type :=
| T_Var2 : forall G T,
G ⊢ tvar2 :: T.
我希望能够为不同的归纳定义定义相同的 Coq 符号,并根据参数的类型区分符号。
这是一个最小的例子:
Inductive type : Type :=
| TBool : type.
Inductive term1 : Type :=
| tvar1 : term1.
Inductive term2 : Type :=
| tvar2 : term2.
Definition context := nat -> (option type).
Reserved Notation "G '⊢' t '::' T" (at level 40, t at level 59).
Inductive typing1 : context -> term1 -> type -> Prop :=
| T_Var1 : forall G T,
G ⊢ tvar1 :: T
where "G '⊢' t1 '::' T" := (typing1 G t1 T)
with typing2 : context -> term2 -> type -> Prop :=
| T_Var2 : forall G T,
G ⊢ tvar2 :: T
where "G '⊢' t2 '::' T" := (typing2 G t2 T).
如您所见,有一个互归纳定义,其中我希望能够对不同类型的术语(term1
和 term2
)使用相同的表示法。
我在尝试编译时遇到的错误是 The term "tvar1" has type "term1" while it is expected to have type "term2".
。
有没有办法让它工作?
我写信给 Coq 邮件列表并收到来自 Gaëtan Gilbert 的 answer,它使用类型 类:
解决了我的问题Inductive type : Type :=
| TBool : type.
Inductive term1 : Type :=
| tvar1 : term1.
Inductive term2 : Type :=
| tvar2 : term2.
Definition context := nat -> (option type).
Class VDash (A B C : Type) := vdash : A -> B -> C -> Prop.
Notation "G '⊢' t '::' T" := (vdash G t T) (at level 40, t at level 59).
Inductive typing1 : VDash context term1 type :=
| T_Var1 : forall G T,
G ⊢ tvar1 :: T
with typing2 : VDash context term2 type :=
| T_Var2 : forall G T,
G ⊢ tvar2 :: T.