Debian Codegraph @

tests-stdlib/test_quotation.v

raw
1 From elpi Require Import elpi.
2
3 Elpi Command test.quotations.
4
5 (****** Notations **********************************)
6
7 Elpi Query lp:{{
8 coq.locate "plus" (const GR),
9 coq.env.const GR (some BO) TY,
10 TY = {{ nat -> nat -> nat }},
11 BO = (fix _ 0 TY add\
12 fun _ {{nat}} n\ fun _ {{nat}} m\
13 match n {{fun _ : nat => nat}}
14 [ m
15 , fun _ {{nat}} w\ app[ {{S}}, app[add,w,m]]]).
16 }}.
17
18 Elpi Query lp:{{
19 coq.locate "plus" (const GR),
20 coq.env.const GR _BO TY,
21 TY = {{ nat -> nat -> nat }},
22 BO1 = (fix _ 0 TY add\
23 {{ fun n m : nat => match n with
24 | O => m
25 | S p => lp:{{ app[add, {{p}}, {{m}}] }}
26 end }}),
27 coq.say BO1,
28 coq.typecheck BO1 _TY2 ok,
29 coq.say BO1.
30 }}.
31
32 From Stdlib Require Vector.
33
34 Elpi Query lp:{{
35 T = {{ fun v : Vector.t nat 2 =>
36 match v with
37 | Vector.nil _ => 0
38 | Vector.cons _ _ _ _ => 1
39 end }},
40 coq.say T,
41 coq.typecheck T _TY ok,
42 coq.say T.
43 }}.
44
45 Elpi Query lp:{{ {{ lp:X }} = 3, coq.say X}}.
46
47 Elpi Query lp:{{ {{ fun x => lp:X x }} = Y, coq.say Y}}.
48 Elpi Program xxx lp:{{
49 pred of i:term, o:term.
50 of X T :- coq.typecheck X T ok.
51 }}.
52 Elpi Query lp:{{
53 X = {{ fun (r : nat) (p : forall y : nat, y = 0 :> nat) (q : bool) => lp:{{ {of {{p}} } }} }}, coq.say X.
54 }}.
55
56 Local Notation inlined_sub_rect :=
57 (fun K K_S u => let (x, Px) as u return K u := u in K_S x Px).
58
59 Unset Auto Template Polymorphism.
60 Record is_SUB (T : Type) (P : T -> bool) (sub_sort : Type) := SubType {
61 val : sub_sort -> T;
62 Sub : forall x, P x = true -> sub_sort;
63 Sub_rect : forall K (_ : forall x Px, K (@Sub x Px)) u, K u;
64 (* SubK : forall x Px, val (@Sub x Px) = x *)
65 }.
66 Axiom leq : nat -> nat -> bool.
67
68 Structure ord u := Ord { oval : nat; prop : leq oval u = true }.
69
70 Check fun u => SubType _ _ _ (oval u) _ inlined_sub_rect.
71
72 Set Debug "elpi".
73 Elpi Query lp:{{ std.do! [
74 coq.say "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
75 T = {{ fun u => SubType _ _ _ (oval u) _ inlined_sub_rect }},
76 coq.say T,
77 coq.say "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
78
79 std.assert-ok! (coq.elaborate-skeleton T _ T1) "does not typecheck",
80 T1 = {{ fun u => SubType _ _ _ _ lp:(X u) _ }},
81 (pi u\ X u = app[global GR, u]) % Rocq <= 9.1
82 ;
83 (pi u\ X u = fun _ _ v\ fun _ _ w\ app[global GR, u, v, w]), % Rocq > 9.1
84 std.assert! (K = global GR, coq.locate "Ord" GR) "not the right constructor"
85 ]
86 }}.
87
88 (* unfortunately the error message does not mention "unknown_inductive" *)
89 Fail Elpi Query lp:{{ std.do! [
90 T = {{ fun u => SubType _ _ _ (oval u) _ inlined_sub_rect }},
91 std.assert-ok! (coq.typecheck T _) "does not typecheck",
92 ]
93 }}.
94
95
96 Fail Check hd.
97 Fail Elpi File boom lp:{{ p :- X = {{ hd }}. }}.
98 Import List.
99 Check hd.
100 Elpi File boom lp:{{ p :- X = {{ hd }}. }}.