Debian Codegraph @

apps/tc/tests/test_coercion.v

raw
1 From elpi Require Import tc.
2
3 Module Animals.
4
5 Module Bird1.
6 Inductive info := Fly | NotFly.
7
8 Class Animal (i : info).
9
10 Class Bird (i : info) := IsAnimal :: Animal i.
11
12 Instance dove : Bird Fly. split. Qed.
13
14 (* It exists a ground solution for tc-Animal *)
15 Elpi Query TC.Solver lp:{{
16 tc-elpi.apps.tc.tests.test_coercion.Animals.Bird1.tc-Animal _ S, ground_term S.
17 }}.
18
19 (* It does not exist a solution for tc-Animal with a flexible solution *)
20 Elpi Query TC.Solver lp:{{
21 not (tc-elpi.apps.tc.tests.test_coercion.Animals.Bird1.tc-Animal _ S, not (ground_term S)).
22 }}.
23
24 Goal Animal Fly. apply _. Qed.
25 Goal Animal NotFly. Fail solve [apply _]. Abort.
26
27 End Bird1.
28
29 Module Bird2.
30
31 Class Animal.
32
33 Class Bird1 := IsAnimal : Animal.
34
35 Instance dove : Bird1. split. Qed.
36
37 (* It does not exists an instance for Animal1 *)
38 Elpi Query TC.Solver lp:{{
39 not (tc-elpi.apps.tc.tests.test_coercion.Animals.Bird2.tc-Animal _).
40 }}.
41
42 Goal Animal. Fail solve [apply _]. apply IsAnimal. Abort.
43
44 End Bird2.
45
46 End Animals.
47
48 Module Vehicle.
49
50 Class Wheels (i: nat).
51
52 Class NoWheels := {
53 (* the first argument of no_wheels is implicit! *)
54 wheels0 :: Wheels 0;
55 }.
56
57 Class Boat := {
58 wheels :: NoWheels
59 }.
60
61 Goal Boat -> Wheels 0.
62 intros.
63 apply _.
64 Qed.
65
66 End Vehicle.
67
68 Module foo.
69 Class B (i : nat).
70
71 Section s.
72 (* Class with coercion depending on section parameters *)
73 Context (A : Type).
74 Class C (i : nat) : Set := {
75 f (x : A) :: B i
76 }.
77 End s.
78 End foo.
79
80 Module foo1.
81 Class B (i : nat).
82
83 Section s.
84 (* Class with coercion not depending on section parameters *)
85 Class C (i : nat) : Set := {
86 f :: B i
87 }.
88 End s.
89
90 Goal C 3 -> B 3.
91 apply _.
92 Abort.
93 End foo1.
94
95 Module localCoercion.
96 Class B (i : nat).
97 Section s.
98 Class C (i : nat) : Set := {
99 #[local] f :: B i
100 }.
101 Goal C 3 -> B 3.
102 apply _.
103 Qed.
104 End s.
105 Goal C 3 -> B 3.
106 Fail apply _.
107 Abort.
108 End localCoercion.