| 1 |
|
| 2 |
|
| 3 |
From elpi Require Import elpi. |
| 4 |
|
| 5 |
Elpi Command declarations. |
| 6 |
Elpi Accumulate lp:{{ |
| 7 |
|
| 8 |
main [indt-decl A] :- !, std.spy-do! [ |
| 9 |
coq.say "raw:" A, |
| 10 |
std.assert-ok! (coq.typecheck-indt-decl A) "Illtyped inductive declaration", |
| 11 |
coq.say "typed:" A, |
| 12 |
coq.env.add-indt A _, |
| 13 |
]. |
| 14 |
main [upoly-indt-decl A UD] :- !, std.spy-do! [ |
| 15 |
coq.say "raw:" A UD, |
| 16 |
coq.univ.print, |
| 17 |
std.assert-ok! (coq.typecheck-indt-decl A) "Illtyped inductive declaration", |
| 18 |
coq.say "typed:" A, |
| 19 |
coq.upoly-decl->attribute UD CL, |
| 20 |
CL => coq.env.add-indt A _, |
| 21 |
]. |
| 22 |
main [const-decl N (some BO) A] :- !, std.spy-do! [ |
| 23 |
coq.arity->term A TY, |
| 24 |
std.assert-ok! (coq.typecheck BO TY) "illtyped definition", |
| 25 |
coq.env.add-const N BO TY _ _, |
| 26 |
]. |
| 27 |
main [upoly-const-decl N (some BO) A UD] :- !, std.spy-do! [ |
| 28 |
coq.arity->term A TY, |
| 29 |
std.assert-ok! (coq.typecheck BO TY) "illtyped definition", |
| 30 |
coq.upoly-decl->attribute UD CL, |
| 31 |
CL => coq.env.add-const N BO TY _ _, |
| 32 |
]. |
| 33 |
main [const-decl N none A] :- !, std.spy-do! [ |
| 34 |
coq.arity->term A TY, |
| 35 |
std.assert-ok! (coq.typecheck-ty TY _) "illtyped axiom", |
| 36 |
coq.env.add-axiom N TY _, |
| 37 |
]. |
| 38 |
main [upoly-const-decl N none A UD] :- !, std.spy-do! [ |
| 39 |
coq.arity->term A TY, |
| 40 |
std.assert-ok! (coq.typecheck-ty TY _) "illtyped axiom", |
| 41 |
coq.upoly-decl->attribute UD CL, |
| 42 |
CL => coq.env.add-axiom N TY _, |
| 43 |
]. |
| 44 |
|
| 45 |
main [ctx-decl (context-item "T" _ _ none t\ |
| 46 |
context-item "x" _ t none _\ |
| 47 |
context-item "l" _ _ (some _) _\ |
| 48 |
context-end)]. |
| 49 |
|
| 50 |
main Args :- coq.error Args. |
| 51 |
}}. |
| 52 |
|
| 53 |
|
| 54 |
#[arguments(raw)] |
| 55 |
Elpi Command raw_declarations. |
| 56 |
Elpi Accumulate lp:{{ |
| 57 |
|
| 58 |
main [indt-decl RA] :- !, std.spy-do! [ |
| 59 |
coq.say "raw:" RA, |
| 60 |
std.assert-ok! (coq.elaborate-indt-decl-skeleton RA A) "Illtyped inductive declaration", |
| 61 |
coq.say "typed:" A, |
| 62 |
coq.env.add-indt A _, |
| 63 |
]. |
| 64 |
main [upoly-indt-decl RA UD] :- !, std.spy-do! [ |
| 65 |
coq.say "raw:" RA UD, |
| 66 |
coq.univ.print, |
| 67 |
@keepunivs! => std.assert-ok! (coq.elaborate-indt-decl-skeleton RA A) "Illtyped inductive declaration", |
| 68 |
coq.say "typed:" A, |
| 69 |
coq.upoly-decl->attribute UD CL, |
| 70 |
CL => coq.env.add-indt A _, |
| 71 |
]. |
| 72 |
main [const-decl N (some RBO) RA] :- !, std.spy-do! [ |
| 73 |
coq.arity->term RA RTY, |
| 74 |
std.assert-ok! (coq.elaborate-ty-skeleton RTY _ TY) "illtyped arity", |
| 75 |
std.assert-ok! (coq.elaborate-skeleton RBO TY BO) "illtyped definition", |
| 76 |
coq.env.add-const N BO TY _ _, |
| 77 |
]. |
| 78 |
main [upoly-const-decl N (some RBO) RA UD] :- !, std.spy-do! [ |
| 79 |
coq.arity->term RA RTY, |
| 80 |
@keepunivs! => std.assert-ok! (coq.elaborate-ty-skeleton RTY _ TY) "illtyped arity", |
| 81 |
@keepunivs! => std.assert-ok! (coq.elaborate-skeleton RBO TY BO) "illtyped definition", |
| 82 |
coq.upoly-decl->attribute UD CL, |
| 83 |
CL => coq.env.add-const N BO TY _ _, |
| 84 |
]. |
| 85 |
main [const-decl N none RA] :- !, std.spy-do! [ |
| 86 |
coq.arity->term RA RTY, |
| 87 |
std.assert-ok! (coq.elaborate-ty-skeleton RTY _ TY) "illtyped axiom", |
| 88 |
coq.env.add-axiom N TY _, |
| 89 |
]. |
| 90 |
main [upoly-const-decl N none RA UD] :- !, std.spy-do! [ |
| 91 |
coq.arity->term RA RTY, |
| 92 |
@keepunivs! => std.assert-ok! (coq.elaborate-ty-skeleton RTY _ TY) "illtyped axiom", |
| 93 |
coq.upoly-decl->attribute UD CL, |
| 94 |
CL => coq.env.add-axiom N TY _, |
| 95 |
]. |
| 96 |
|
| 97 |
main [ctx-decl (context-item "T" _ _ none t\ |
| 98 |
context-item "x" _ t none _\ |
| 99 |
context-item "l" _ _ (some _) _\ |
| 100 |
context-end)]. |
| 101 |
|
| 102 |
main Args :- coq.error Args. |
| 103 |
}}. |
| 104 |
|
| 105 |
|
| 106 |
(*****************************************) |
| 107 |
|
| 108 |
Module inductive_nup. |
| 109 |
Elpi declarations |
| 110 |
Inductive foo1 {A1} (A2 : A1) | (B1 B2 : Type) : nat -> Type := |
| 111 |
| a_k1 : forall x, foo1 (B1 * B1)%type B2 3 -> foo1 B1 B2 x |
| 112 |
| a_k2 : A1 -> foo1 B1 B2 1. |
| 113 |
Check foo1 _ _ _ _ : Type. |
| 114 |
Fail Check (foo1 _ _ _ _ _). |
| 115 |
Check a_k1 _ _ _ 3 _ : foo1 _ _ _ 3. |
| 116 |
Unset Auto Template Polymorphism. |
| 117 |
Inductive r (A : Type) (a : A) := R { f :> A -> A; g : A; p : a = g }. |
| 118 |
End inductive_nup. |
| 119 |
|
| 120 |
Module raw_inductive_nup. |
| 121 |
Elpi raw_declarations |
| 122 |
Inductive foo1 {A1} (A2 : A1) | (B1 B2 : Type) : nat -> Type := |
| 123 |
| a_k1 : forall x, foo1 (B1 * B1)%type B2 3 -> foo1 B1 B2 x |
| 124 |
| a_k2 : A1 -> foo1 B1 B2 1. |
| 125 |
Check foo1 _ _ _ _ : Type. |
| 126 |
Fail Check (foo1 _ _ _ _ _). |
| 127 |
Check a_k1 _ _ _ 3 _ : foo1 _ _ _ 3. |
| 128 |
Unset Auto Template Polymorphism. |
| 129 |
Inductive r (A : Type) (a : A) := R { f :> A -> A; g : A; p : a = g }. |
| 130 |
End raw_inductive_nup. |
| 131 |
|
| 132 |
Module more_nup. |
| 133 |
Inductive t (A : Type) (y : nat) : Type := |
| 134 |
| K (x : A) {n : nat} : t A n -> t A y. |
| 135 |
|
| 136 |
(* issue #383 *) |
| 137 |
Elpi Query lp:{{ |
| 138 |
coq.locate "t" (indt I), |
| 139 |
coq.env.indt-decl I D, |
| 140 |
std.assert! (D = |
| 141 |
parameter "A" explicit (sort (typ _)) c0 \ |
| 142 |
inductive "t" tt |
| 143 |
(parameter "y" explicit (global (indt _)) c1 \ |
| 144 |
arity (sort (typ _))) c1 \ |
| 145 |
[constructor "K" |
| 146 |
(parameter "y" explicit (global (indt _)) c2 \ |
| 147 |
parameter "x" explicit c0 c3 \ |
| 148 |
parameter "n" maximal (global (indt _)) c4 \ |
| 149 |
arity (prod `_` (app [c1, c4]) c5 \ app [c1, c2]))]) "wrong HOAS nup". |
| 150 |
}}. |
| 151 |
|
| 152 |
End more_nup. |
| 153 |
|
| 154 |
(*****************************************) |
| 155 |
Module anonymous_fields. |
| 156 |
Elpi declarations |
| 157 |
Record foo := { |
| 158 |
f : nat -> nat; |
| 159 |
_ : f 0 = 0; |
| 160 |
}. |
| 161 |
Fail Check _elpi_ctx_entry_2_. |
| 162 |
End anonymous_fields. |
| 163 |
|
| 164 |
Module raw_anonymous_fields. |
| 165 |
Elpi raw_declarations |
| 166 |
Record foo := { |
| 167 |
f : nat -> nat; |
| 168 |
_ : f 0 = 0; |
| 169 |
}. |
| 170 |
Fail Check _elpi_ctx_entry_2_. |
| 171 |
End raw_anonymous_fields. |
| 172 |
|
| 173 |
(*****************************************) |
| 174 |
|
| 175 |
Module record_attributes0. |
| 176 |
Record foo A (B : A) : Type := { |
| 177 |
a (_: A) (_ : A) : A; |
| 178 |
z (a : A) :> B = B -> A; |
| 179 |
#[canonical=no] |
| 180 |
x (w := 3) : forall x, a x x = x; |
| 181 |
}. |
| 182 |
Elpi Query lp:{{ |
| 183 |
coq.locate "foo" (indt I), |
| 184 |
coq.env.projections I [some A, some B, some C], |
| 185 |
coq.CS.canonical-projection? A, |
| 186 |
coq.CS.canonical-projection? B, |
| 187 |
not (coq.CS.canonical-projection? C). |
| 188 |
}}. |
| 189 |
End record_attributes0. |
| 190 |
|
| 191 |
|
| 192 |
Module record_attributes. |
| 193 |
Elpi declarations |
| 194 |
Record foo A (B : A) : Type := { |
| 195 |
a (_: A) (_ : A) : A; |
| 196 |
z (a : A) :> B = B -> A; |
| 197 |
#[canonical=no] |
| 198 |
x (w := 3) : forall x, a x x = x; |
| 199 |
}. |
| 200 |
Elpi Query lp:{{ |
| 201 |
coq.locate "foo" (indt I), |
| 202 |
coq.env.projections I [some A, some B, some C], |
| 203 |
coq.CS.canonical-projection? A, |
| 204 |
coq.CS.canonical-projection? B, |
| 205 |
not (coq.CS.canonical-projection? C). |
| 206 |
}}. |
| 207 |
End record_attributes. |
| 208 |
|
| 209 |
Module raw_record_attributes. |
| 210 |
Elpi raw_declarations |
| 211 |
Record foo A (B : A) : Type := { |
| 212 |
a (_: A) (_ : A) : A; |
| 213 |
z (a : A) :> B = B -> A; |
| 214 |
#[canonical=no] |
| 215 |
x (w := 3) : forall x, a x x = x; |
| 216 |
}. |
| 217 |
Elpi Query lp:{{ |
| 218 |
coq.locate "foo" (indt I), |
| 219 |
coq.env.projections I [some _, some _, some _]. |
| 220 |
}}. |
| 221 |
End raw_record_attributes. |
| 222 |
|
| 223 |
(*****************************************) |
| 224 |
|
| 225 |
Module definition. |
| 226 |
Elpi declarations |
| 227 |
Definition x1 (P : Type) (w : P) (n : nat) := (n + 1). |
| 228 |
Check x1 : forall P, P -> nat -> nat. |
| 229 |
Check refl_equal _ : x1 = fun P w n => n + 1. |
| 230 |
Elpi declarations Axiom y (n : nat) : Type. |
| 231 |
Check y : nat -> Type. |
| 232 |
End definition. |
| 233 |
|
| 234 |
Module raw_definition. |
| 235 |
Elpi raw_declarations |
| 236 |
Definition x1 (P : Type) (w : P) (n : nat) := (n + 1). |
| 237 |
Check x1 : forall P, P -> nat -> nat. |
| 238 |
Check refl_equal _ : x1 = fun P w n => n + 1. |
| 239 |
Elpi declarations Axiom y (n : nat) : Type. |
| 240 |
Check y : nat -> Type. |
| 241 |
End raw_definition. |
| 242 |
|
| 243 |
(*****************************************) |
| 244 |
|
| 245 |
Module section. |
| 246 |
Elpi declarations Context T (x : T) (l := 3). |
| 247 |
End section. |
| 248 |
|
| 249 |
Module raw_section. |
| 250 |
Elpi raw_declarations Context T (x : T) (l := 3). |
| 251 |
End raw_section. |
| 252 |
|
| 253 |
|
| 254 |
(*****************************************) |
| 255 |
|
| 256 |
Module full_definition. |
| 257 |
Elpi declarations |
| 258 |
Definition x (n : nat) := Eval compute in (1 + n). |
| 259 |
Goal x 1 = 2. |
| 260 |
unfold x. |
| 261 |
match goal with |- 2 = 2 => reflexivity end. |
| 262 |
Qed. |
| 263 |
Definition y (n : nat) : nat := ltac:(exact 1 + n). |
| 264 |
End full_definition. |
| 265 |
|
| 266 |
(*****************************************) |
| 267 |
|
| 268 |
Module copy. |
| 269 |
Import inductive_nup. |
| 270 |
|
| 271 |
Elpi Query lp:{{ |
| 272 |
coq.locate "foo1" (indt I), |
| 273 |
coq.env.indt-decl I D, |
| 274 |
coq.say D, |
| 275 |
coq.env.add-indt D _. |
| 276 |
}}. |
| 277 |
Check foo1 _ _ _ _ : Type. |
| 278 |
Fail Check (foo1 _ _ _ _ _). |
| 279 |
Check a_k1 _ _ _ 3 _ : foo1 _ _ _ 3. |
| 280 |
|
| 281 |
|
| 282 |
Elpi Query lp:{{ |
| 283 |
coq.locate "r" (indt I), |
| 284 |
coq.env.indt-decl I R, |
| 285 |
std.assert! (R = |
| 286 |
parameter "A" explicit (sort (typ _)) c0 \ |
| 287 |
parameter "a" explicit c0 c1 \ |
| 288 |
record "r" (sort (typ _)) "R" |
| 289 |
(field [coercion reversible,canonical tt] "f" (prod `_` c0 _\ c0) c2\ |
| 290 |
field [coercion off,canonical tt] "g" c0 c3\ |
| 291 |
field [coercion off,canonical tt] "p" (app [global (indt _), c0, c1, c3]) _\ |
| 292 |
end-record)) "not a record", |
| 293 |
coq.env.add-indt R _. |
| 294 |
}}. |
| 295 |
|
| 296 |
Print r. |
| 297 |
End copy. |
| 298 |
|
| 299 |
Set Printing Universes. |
| 300 |
|
| 301 |
(*****************************************) |
| 302 |
|
| 303 |
Elpi declarations #[universes(template=no)] Inductive X1 : Type := . |
| 304 |
Fail Elpi declarations #[universes(template)] Inductive X2 : Type := . |
| 305 |
About X1. |
| 306 |
|
| 307 |
Fail Elpi Query lp:{{ coq.locate "X1" GR, coq.env.global GR (pglobal GR _) }}. |
| 308 |
|
| 309 |
(*****************************************) |
| 310 |
|
| 311 |
Elpi declarations #[universes(polymorphic)] Inductive X3 : Type := . |
| 312 |
Elpi declarations #[universes(polymorphic,cumulative)] Inductive X4 : Type := . |
| 313 |
About X3. |
| 314 |
About X4. |
| 315 |
|
| 316 |
Elpi Query lp:{{ coq.locate "X3" GR, coq.env.global GR (pglobal GR _) }}. |
| 317 |
Elpi Query lp:{{ coq.locate "X4" GR, coq.env.global GR (pglobal GR _) }}. |
| 318 |
|
| 319 |
Elpi declarations #[universes(polymorphic)] Inductive X5@{u} : Type@{u} := . |
| 320 |
About X5. |
| 321 |
|
| 322 |
Elpi declarations #[universes(polymorphic)] Inductive X6@{u v|u<v} : Type@{v} := K (u : Type@{u}). |
| 323 |
About X6. |
| 324 |
|
| 325 |
Fail Elpi raw_declarations #[universes(polymorphic)] Inductive X7@{u v|u<v} : Type@{v} := K (u : Type@{u}). |
| 326 |
|
| 327 |
Elpi raw_declarations #[universes(polymorphic)] Inductive X8 : Type := . |
| 328 |
About X8. |
| 329 |
|
| 330 |
(* ******************** *) |
| 331 |
Elpi declarations #[universes(polymorphic)] Definition f1 (T:Type) (x:T) := x. |
| 332 |
About f1. |
| 333 |
|
| 334 |
Elpi declarations #[universes(polymorphic)] Definition f2@{u} (T:Type@{u}) (T1:Type@{u}) (x:T) := x. |
| 335 |
About f2. |
| 336 |
|
| 337 |
Elpi raw_declarations #[universes(polymorphic)] Definition f3 (T:Type) (x:T) := x. |
| 338 |
About f3. |
| 339 |
|
| 340 |
Elpi raw_declarations #[universes(polymorphic)] Definition f4@{u} (T:Type@{u}) (T1:Type@{u}) (x:T) := x. |
| 341 |
About f4. |
| 342 |
|
| 343 |
Universe uuu. |
| 344 |
|
| 345 |
Elpi raw_declarations Definition f5 (T:Type@{uuu}) (T1:Type@{uuu}) (x:T) := x. |
| 346 |
Fail Elpi declarations Definition f6@{uuux} (T:Type@{uuu}) (T1:Type@{uuux}) (x:T) := x. |
| 347 |
Fail Elpi raw_declarations Definition f6@{uuux} (T:Type@{uuu}) (T1:Type@{uuux}) (x:T) := x. |
| 348 |
|
| 349 |
Set Universe Polymorphism. |
| 350 |
Elpi declarations Definition f6@{uuux} (T:Type@{uuu}) (T1:Type@{uuux}) (x:T) := x. |
| 351 |
About f6. |
| 352 |
|
| 353 |
Fail Elpi declarations Definition f7 := f6@{Prop}. |
| 354 |
Fail Elpi raw_declarations Definition f7 := f6@{Prop}. |
| 355 |
|
| 356 |
Elpi declarations Definition f7 := f6@{Set}. |
| 357 |
Elpi raw_declarations Definition f8 := f6@{Set}. |
| 358 |
|
| 359 |
Elpi declarations Definition f7' := f6@{uuu}. |
| 360 |
Elpi raw_declarations Definition f8' := f6@{uuu}. |
| 361 |
|
| 362 |
Elpi declarations Definition f7''@{x} := f6@{x}. |
| 363 |
Elpi raw_declarations Definition f8''@{x} := f6@{x}. |
| 364 |
|
| 365 |
(* ******************** *) |
| 366 |
Unset Universe Polymorphism. |
| 367 |
|
| 368 |
Class I := {}. |
| 369 |
Class L (i : I) := {}. |
| 370 |
|
| 371 |
(*#[arguments(raw)] *) |
| 372 |
Elpi Command bug_394. |
| 373 |
Elpi Accumulate lp:{{ |
| 374 |
main [A,B,C] :- |
| 375 |
coq.say A B C, |
| 376 |
std.assert! (A = |
| 377 |
const-decl "D" |
| 378 |
(some (fun `i` _ c0 \ fun `l` (app [{{ L }}, c0]) c1 \ {{ True }})) |
| 379 |
(parameter "i" maximal _ c0 \ |
| 380 |
parameter "l" maximal (app [{{ L }}, c0]) c1 \ |
| 381 |
arity (sort prop))) |
| 382 |
"not ok 1", |
| 383 |
std.assert! (B = |
| 384 |
const-decl "D" |
| 385 |
(some (fun `i` _ c0 \ fun `l` (app [{{ L }}, c0]) c1 \ {{ True }})) |
| 386 |
(parameter "i" maximal _ c0 \ |
| 387 |
parameter _ maximal (app [{{ L }}, c0]) c1 \ |
| 388 |
arity (sort prop))) |
| 389 |
"not ok 2", |
| 390 |
std.assert! (C = |
| 391 |
const-decl "D" |
| 392 |
(some (fun `i` _ c0 \ fun `l` (app [{{ L }}, c0]) c1 \ fun _ {{nat}} c2\ {{ True }})) |
| 393 |
(parameter "i" maximal _ c0 \ |
| 394 |
parameter _ maximal (app [{{ L }}, c0]) c1 \ |
| 395 |
parameter "n" explicit {{ nat }} c2\ |
| 396 |
arity (sort prop))) |
| 397 |
"not ok 3" |
| 398 |
. |
| 399 |
|
| 400 |
}}. |
| 401 |
|
| 402 |
|
| 403 |
Elpi bug_394 |
| 404 |
Definition D `{l : L} : Prop := True |
| 405 |
Definition D `{L} : Prop := True |
| 406 |
Definition D `{L} (n:nat) : Prop := True |
| 407 |
. |
| 408 |
|
| 409 |
Elpi Tactic open. |
| 410 |
Elpi Accumulate lp:{{ |
| 411 |
solve (goal _ _ _ _ [open-trm N X]) _ :- coq.say N X. |
| 412 |
}}. |
| 413 |
Goal True. |
| 414 |
elpi open `(x + y). |
| 415 |
Abort. |