gpt4 book ai didi

coq - Coq 中不同类型的重载符号

转载 作者:行者123 更新时间:2023-12-04 13:48:59 25 4
gpt4 key购买 nike

我希望能够为不同的归纳定义定义相同的 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).

如您所见,有一个相互归纳的定义,我希望能够对不同类型的术语( term1term2 )使用相同的表示法。

我在尝试编译时遇到的错误是 The term "tvar1" has type "term1" while it is expected to have type "term2". .

有没有办法让这个工作?

最佳答案

我写信给 Coq 邮件列表并收到了 answer来自 Gaëtan Gilbert 使用类型类解决了我的问题:

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 - Coq 中不同类型的重载符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44034734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com