| 1 |
From elpi Require Import elpi. |
| 2 |
|
| 3 |
Elpi Command TCCS. |
| 4 |
|
| 5 |
(****** TC **********************************) |
| 6 |
|
| 7 |
Require Import Classes.RelationClasses. |
| 8 |
|
| 9 |
Axiom T : Type. |
| 10 |
Axiom R : T -> T -> Prop. |
| 11 |
Axiom Rr : forall x : T, R x x. |
| 12 |
|
| 13 |
Definition myi : Reflexive R. |
| 14 |
Proof. |
| 15 |
exact Rr. |
| 16 |
Defined. |
| 17 |
|
| 18 |
Fail Example ex : Reflexive R := _. |
| 19 |
|
| 20 |
Module TCLocal. |
| 21 |
Elpi Query lp:{{ coq.locate "myi" GR, @local! => coq.TC.declare-instance GR 10. }}. |
| 22 |
Succeed Example ex : Reflexive R := _. |
| 23 |
End TCLocal. |
| 24 |
|
| 25 |
Module TCExport. |
| 26 |
Fail Example ex : Reflexive R := _. |
| 27 |
Module Mod. |
| 28 |
Elpi Query lp:{{ coq.locate "myi" GR, coq.TC.declare-instance GR 10. }}. |
| 29 |
End Mod. |
| 30 |
Fail Example ex : Reflexive R := _. |
| 31 |
Import Mod. |
| 32 |
Check (_ : Reflexive R). |
| 33 |
Succeed Example ex : Reflexive R := _. |
| 34 |
End TCExport. |
| 35 |
|
| 36 |
Module TCGlobal. |
| 37 |
Elpi Query lp:{{ coq.locate "myi" GR, @global! => coq.TC.declare-instance GR 10. }}. |
| 38 |
End TCGlobal. |
| 39 |
Succeed Example ex : Reflexive R := _. |
| 40 |
|
| 41 |
|
| 42 |
Elpi Query lp:{{coq.TC.db L}}. |
| 43 |
Elpi Query lp:{{coq.locate "RewriteRelation" GR, coq.TC.db-for GR L}}. |
| 44 |
Elpi Query lp:{{coq.locate "RewriteRelation" GR, coq.TC.class? GR}}. |
| 45 |
Elpi Query lp:{{coq.locate "True" GR, not(coq.TC.class? GR)}}. |
| 46 |
|
| 47 |
Module hint_instance. |
| 48 |
Class Test : Prop := {}. |
| 49 |
|
| 50 |
Instance instance_c : Test := Build_Test. |
| 51 |
Instance instance_g : Test | 4 := Build_Test. |
| 52 |
|
| 53 |
Definition hint_c : Test := Build_Test. |
| 54 |
Definition hint_g : Test := Build_Test. |
| 55 |
|
| 56 |
Hint Resolve hint_c : typeclass_instances. |
| 57 |
Hint Resolve hint_g | 5 : typeclass_instances. |
| 58 |
|
| 59 |
Elpi Command test. |
| 60 |
Elpi Accumulate lp:{{ |
| 61 |
pred expected o:tc-instance. |
| 62 |
expected (tc-instance {{:gref hint_c}} 0). |
| 63 |
expected (tc-instance {{:gref instance_c}} 0). |
| 64 |
expected (tc-instance {{:gref instance_g}} 4). |
| 65 |
% Note: the priority of hint_g is 5, the one given in the hint resolve |
| 66 |
expected (tc-instance {{:gref hint_g}} 5). |
| 67 |
}}. |
| 68 |
Elpi Query lp:{{ |
| 69 |
coq.TC.db-for {{:gref Test}} L, |
| 70 |
std.length L 4, % there are 4 instances for Test |
| 71 |
std.findall (expected _) Exp, % get the expected prio |
| 72 |
(Check: (pred i:prop)) = (x\ sigma Exp\ x = expected Exp, std.mem L Exp), |
| 73 |
std.forall Exp Check. % check each instance has the expected priority |
| 74 |
}}. |
| 75 |
|
| 76 |
End hint_instance. |
| 77 |
|
| 78 |
Axiom C : Type -> Type. |
| 79 |
|
| 80 |
Elpi Query lp:{{ coq.TC.declare-class {{:gref C }} }}. |
| 81 |
|
| 82 |
Axiom c : C nat. |
| 83 |
|
| 84 |
#[local] Instance foox : C nat := c. |
| 85 |
|
| 86 |
(****** CS **********************************) |
| 87 |
|
| 88 |
Structure eq := mk_eq { carrier : Type; eq_op : carrier -> carrier -> bool; _ : nat }. |
| 89 |
|
| 90 |
Axiom W : Type. |
| 91 |
Axiom Z : W -> W -> bool. |
| 92 |
Axiom t : W. |
| 93 |
|
| 94 |
Definition myc : eq := mk_eq W Z 3. |
| 95 |
|
| 96 |
Fail Check (eq_op _ t t). |
| 97 |
|
| 98 |
Elpi Query lp:{{coq.locate "myc" GR, coq.CS.declare-instance GR.}}. |
| 99 |
|
| 100 |
Check (eq_op _ t t). |
| 101 |
|
| 102 |
Elpi Query lp:{{ coq.CS.db L }}. |
| 103 |
|
| 104 |
Elpi Query lp:{{ |
| 105 |
coq.locate "eq" (indt I), |
| 106 |
coq.env.projections I [some P1, some P2, none], |
| 107 |
coq.locate "carrier" (const P1), |
| 108 |
coq.locate "eq_op" (const P2) |
| 109 |
}}. |
| 110 |
|
| 111 |
Axiom W1 : Type. |
| 112 |
Axiom Z1 : W1 -> W1 -> bool. |
| 113 |
Axiom t1 : W1. |
| 114 |
|
| 115 |
Definition myc1 : eq := mk_eq W1 Z1 3. |
| 116 |
|
| 117 |
Section CStest. |
| 118 |
Elpi Query lp:{{ coq.locate "myc1" GR, @local! => coq.CS.declare-instance GR. }}. |
| 119 |
|
| 120 |
Check (eq_op _ t1 t1). |
| 121 |
|
| 122 |
Elpi Query lp:{{ coq.locate "eq_op" P, coq.CS.db-for P _ [_,_] }}. |
| 123 |
|
| 124 |
Elpi Query lp:{{ coq.locate "W" W, coq.CS.db-for _ (cs-gref W) [_] }}. |
| 125 |
|
| 126 |
Elpi Query lp:{{ coq.locate "eq_op" P, coq.locate "Z1" W, coq.CS.db-for P (cs-gref W) L, coq.say L, L = [cs-instance P (cs-gref W) {{:gref myc1}}] }}. |
| 127 |
|
| 128 |
Elpi Query lp:{{ coq.locate "eq_op" P, coq.locate "nat" W, coq.CS.db-for P (cs-gref W) [] }}. |
| 129 |
|
| 130 |
|
| 131 |
End CStest. |
| 132 |
|
| 133 |
Fail Check (eq_op _ t1 t1). |
| 134 |
|
| 135 |
|
| 136 |
(****** Coercions **********************************) |
| 137 |
|
| 138 |
Axiom C1 : Type. |
| 139 |
Axiom C2 : Type. |
| 140 |
Axiom c12 : C1 -> C2. |
| 141 |
Axiom c1t : C1 -> Type. |
| 142 |
Axiom c1f : C1 -> nat -> nat. |
| 143 |
|
| 144 |
Elpi Query lp:{{ |
| 145 |
coq.locate "c12" GR1, |
| 146 |
coq.locate "c1t" GR2, |
| 147 |
coq.locate "c1f" GR3, |
| 148 |
coq.locate "C1" C1, |
| 149 |
% coq.locate "C2" C2, |
| 150 |
(@global! => coq.coercion.declare (coercion GR1 _ _ _)), |
| 151 |
(@global! => coq.coercion.declare (coercion GR2 _ C1 sortclass)), |
| 152 |
(@global! => coq.coercion.declare (coercion GR3 _ C1 funclass)). |
| 153 |
}}. |
| 154 |
|
| 155 |
Check (fun x : C1 => (x : C2)). |
| 156 |
Check (fun x : C1 => fun y : x => true). |
| 157 |
Check (fun x : C1 => x 3). |
| 158 |
|
| 159 |
Elpi Query lp:{{coq.coercion.db L}}. |
| 160 |
|
| 161 |
Axiom C3 : nat -> Type. |
| 162 |
Axiom nuc : forall x, C1 -> C3 x. |
| 163 |
|
| 164 |
Set Warnings "-uniform-inheritance". |
| 165 |
Elpi Query lp:{{ @reversible! => coq.coercion.declare (coercion {coq.locate "nuc"} _ _ _) }}. |
| 166 |
|
| 167 |
About nuc. |
| 168 |
|