首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Coq表示法中的重载算子

Coq表示法中的重载算子
EN

Stack Overflow用户
提问于 2017-05-03 14:44:25
回答 1查看 574关注 0票数 3

我想为几种判断创建符号,例如打字和子类型关系:

代码语言:javascript
复制
Reserved Notation "Г '⊢' t '∈' T" (at level 40).
Reserved Notation "Г '⊢' T '<:' U" (at level 40).

Inductive typing_relation : context -> term -> type -> Prop := ...
where "Γ '⊢' t '∈' T" := (typing_relation Γ t T).

Inductive subtyping_relation : context -> type -> type -> Prop := ...
where "Г '⊢' T '<:' U" := (subtyping_relation Γ T U).

据我所知,Coq将不允许这样做,因为运算符在这些定义中被重载。

如何使Coq根据其参数类型(例如,type) (和/或基于符号中的其他操作符,例如 vs <:)推断重载运算符的定义(在本例中是)?

(请注意,使用不同的符号不是一种选择,因为我的Coq程序定义了几个类型和子类型关系。)

编辑:下面是一个很小的例子:

代码语言:javascript
复制
Inductive type : Type :=
  | TBool : type.

Inductive term : Type :=
  | tvar : nat -> term.

Definition context := nat -> (option type).

Reserved Notation "G '⊢' t '∈' T" (at level 40).

Inductive typing_relation : context -> term -> type -> Prop :=
 | T_Var : forall G x T,
      G x = Some T ->
      G ⊢ tvar x ∈ T
 where "G '⊢' t '∈' T" := (typing_relation G t T).

Reserved Notation "G '⊢' T '<:' U" (at level 40).

Inductive subtype_relation : context -> type -> type -> Prop :=
  | S_Refl : forall G T,
      G ⊢ T <: T
  where "G '⊢' T '<:' U" := (subtype_relation G T U).

这将导致错误:

代码语言:javascript
复制
Syntax error: '<:' or '∈' expected after [constr:operconstr level 200] (in [constr:operconstr]).
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-03 16:47:12

原因是您不能那样使用<:,因为<:已经被定义为Coq的排版符号。它的作用就好像它是这样定义的。

代码语言:javascript
复制
Reserved Notation "t <: T" (at level 100, right associativity).

这种情况类似于“Coq参考手册”(第12.1.3节)所述的情况:

但是,在最后一种情况下,与类型转换的表示法存在冲突。最后一个表示法,如命令Print Grammar constr.所示,在100级。为了避免将x : A解析为类型强制转换,有必要将x设置在100以下(通常为99 )。

以下是解决您的情况的一个可能的解决方案:

代码语言:javascript
复制
Reserved Notation "G '⊢' t '∈' T" (at level 40, t at level 99).
Reserved Notation "G '⊢' T '<:' U" (at level 40, T at level 99).
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43763304

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档