2017-05-03 31 views
3

我想對幾種判斷創建符號,例如用於打字和子類型關係:在勒柯克運算符重載符號

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). 

據我瞭解,勒柯克不會允許這種情況是因爲操作在這些定義中被重載。

我如何才能讓勒柯克推斷重載運算符的定義(在這種情況下,)的基礎上的類型的參數(如term VS type)(和/或基於被部分其他運營商符號,例如 vs <:)?

(請注意,使用不同的符號會不會是一種選擇,因爲我的勒柯克程序定義了幾種類型和子類型的關係。)

編輯:這裏是一個小例子:

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). 

這導致錯誤:

Syntax error: '<:' or '∈' expected after [constr:operconstr level 200] (in [constr:operconstr]). 
+0

你會得到什麼錯誤信息?另外,[mcve]會很好。 –

+0

剛剛添加了一個例子! – amaurremi

+1

[Here](http://stackoverflow.com/questions/42239138/syntax-error-with-in-coq-notations)是一個相關的問題。 –

回答

2

的原因是,你不能使用<:這樣的,因爲<:已經被定義爲勒柯克的typecast notation。它的作用,如果它是像這樣

Reserved Notation "t <: T" (at level 100, right associativity). 

所述的情況是類似於在Coq的參考手冊中所描述的(§12.1.3):

In the last case though, there is a conflict with the notation for type casts. This last notation, as shown by the command Print Grammar constr. is at level 100. To avoid x : A being parsed as a type cast, it is necessary to put x at a level below 100, typically 99.

這裏是您的情況可能的解決方案:

Reserved Notation "G '⊢' t '∈' T" (at level 40, t at level 99). 
Reserved Notation "G '⊢' T '<:' U" (at level 40, T at level 99). 
+0

此更改使上述代碼得以編譯。但是,我無法真正使用符號。以下代碼: '定義t1 G t T:= G⊢t∈T.'在[constr:operconstr level 99](in [constr:operconstr])之後導致錯誤「Syntax error:'<:'。 ' – amaurremi

+1

Coq正在使用LL1解析器,因此您需要修改以相同標記開頭的所有符號。我更新了答案。 –