Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Overloading notation for different types in Coq

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Overloading notation for different types in Coq


Chronological Thread 
  • From: Gaetan Gilbert <gaetan.gilbert AT ens-lyon.fr>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] Overloading notation for different types in Coq
  • Date: Thu, 18 May 2017 20:05:42 +0200
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=gaetan.gilbert AT ens-lyon.fr; spf=Neutral smtp.mailfrom=gaetan.gilbert AT ens-lyon.fr; spf=None smtp.helo=postmaster AT labbe.ens-lyon.fr
  • Ironport-phdr: 9a23:IJkc0R+xPdc8U/9uRHKM819IXTAuvvDOBiVQ1KB30+McTK2v8tzYMVDF4r011RmSDNudtq0My7KP9fuxBipYudfJmUtBWaIPfidGs/lepxYnDs+BBB+zB9/RRAt+Iv5/UkR49WqwK0lfFZW2TVTTpnqv8WxaQU2nZkJ6KevvB4Hdkdm82fys9J3PeQVIgye2ba9vIBmsowjcssgbjZFiJ6sz1xDFpmdEd/lMyW5mIV+enQzw6tus8JJm7i9dp+8v+8lcXKr1eKg1UaZWADM6PW4r+cblrwPDTQyB5nsdVmUZjB9FCBXb4R/5Q5n8rDL0uvJy1yeGM8L2S6s0WSm54KdwVBDokiYHOCUn/2zRl8d9kbhUoBOlpxx43o7UfISYP+dwc6/BYd8XQ3dKU8BMXCJDH4y8dZMCAfcfM+ZWr4fzpFUAohWxCgauGOzi0TpIimPs0KAgz+gsHwPL0Qo9FNwOqnTUq9D1Ob8TX++v0qbI0S/Mb/VL0jn86YjIdgsuru+WXbJsbMHczkYvGBnbgVWMs4PlOSmZ1usMs2if9OVvS/ivi3I8pg5vpDiv3d4gio3Jh4ISzFDI7yt5wJwsKNC+VUV1YsakHYNNuyyVK4d6WMEvTmNytCony7ALu4S3cDYUxJg53xLTdeGLfoaS7h7+VOudPy10iG9kdb6hnRq+7EqtxvH6W8KpylhFtDBFncPJtn0V1xzc9MyHSvxl80elwzmAzBvc5f9eLU8qk6rbMIctwrowl5oUt0TPBCH2mF/ugK+XcEUr5PSo5vz6brjpupOQLY15hwPkPqgzm8GyA/40PhYQU2SF4ei80afs/Uz9QLVElP02lazZvYjVJcsBuKG5HxVa0oA55xawDjem1M8XkmcdLFJZYx+IkY7pO0rXLPD8Dfa/hFKsnC1lx/DcJrHhGInCLmDfkLf9erZw81JTyA0qzdxG+51UDqwBL+noV0/qtN3YCwc5PBauz+bmDtV9zIIeVniVDq+XKqOB+WOPs+koOqyHYJIfkDf7MfksofD03lEjnlpIUqCkwZIRIF+5Gv5rOVnRNXXlj8sIFyEFvw40Qfb2oFCESntXdnG0GawmsGJoQLm6BJvOE9j+yIeK2z22S8Vb

With typeclasses you can do something like see attached file.

Gaëtan Gilbert

On 18/05/2017 19:57, Marianna Rapoport wrote:
I would like to be able to define the same Coq notations for different inductive definitions, and distinguish the notations based on the types of their arguments.

Here is a minimal example:

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 x T,
G ⊢ tvar2 :: T
where "G '⊢' t2 '::' T" := (typing2 G t2 T).

As you see, there is a mutually inductive definition, in which I'd like to be able to use the same notation for different types of terms (`term1` and `term2`).

The error I get when trying to compile this is `Error: Illegal application (Non-functional construction): The expression "tvar1" of type "term1" cannot be applied to the term "x" : "?T"`.

Is there a way to get this to work, maybe by using type classes?

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.



Archive powered by MHonArc 2.6.18.

Top of Page