Debian Codegraph @

test-suite/success/reverse_coercions.v

raw
1 Module Test0.
2
3 (* By default all coercions from a Structure/Record are also reversible, unless:
4
5 Structure foo := {
6 ..
7 #[reversible=no] bla :> blu
8 }
9
10 is given
11 *)
12
13 (* Declaring/undeclaring a reverse coercion after the facts:
14
15 #[reversible] Coercion sort.
16 #[reversible=yes] Coercion sort.
17
18 #[reversible=no] Coercion sort.
19 *)
20
21 Structure S := {
22 ssort :> Type;
23 sstuff : ssort;
24 }.
25
26 Definition test1 (s : S) (x : s) := sstuff s.
27 Definition test2 (s : S) := sstuff s.
28
29 Canonical Structure S_nat := {| ssort := nat; sstuff := 0; |}.
30 Set Printing All.
31 Check test1 _ (0 : nat).
32
33 (* old hack *)
34 Definition test' {s : S} (t : Type) (f : ssort s -> t) := sstuff s.
35 Notation test t := (test' t (fun x => x)).
36 Check test nat.
37
38 (* new *)
39 Check test2 (nat : Type).
40 Definition nat' (x:unit) := nat.
41 Arguments nat' &.
42 (* checks that reapply_coercions gets the right trace *)
43 Check test2 (nat' tt).
44 Check (nat : S).
45
46 Structure R := {
47 rsort :> Type;
48 rstuff : rsort;
49 srstuff : rsort;
50 }.
51
52 Coercion RtoS (r : R) := {| ssort := rsort r ; sstuff := srstuff r|}.
53 Canonical RtoS.
54
55 Canonical Structure R_nat := {| rsort := nat; rstuff := 1; srstuff := 0 |}.
56
57 Definition test3 (r : R) := rstuff r.
58
59 Set Printing All.
60 Check test3 nat.
61 Check test3 S_nat.
62
63 Structure T := {
64 tsort :> Type;
65 }.
66
67 Canonical T_nat (x : unit) := {| tsort := nat |}.
68
69 Check test2 (T_nat tt).
70
71
72
73 Structure A := { }.
74 Structure A' := { }.
75 Structure B := { ba :> A; #[canonical=no] ba' :> A' }.
76 Structure C := { ca :> A; #[canonical=no] ca' :> A' }.
77 Axiom f : A -> A'.
78 Coercion f : A >-> A'.
79
80 Canonical b : B := {| ba := Build_A; ba' := Build_A' |}.
81 Canonical c : C := {| ca := Build_A; ca' := Build_A' |}.
82
83 Definition test4 (x : B) := 1.
84 Check test4 c.
85
86
87
88
89
90
91 (* ~~> test S_nat : S_nat.sort
92 Type ==?== S
93 :
94 f : nat ---> S_nat
95
96 sort : S >-> Type
97
98 f :=
99 nat ----> ?x
100 sort ?x ==?== nat
101 *)
102
103 End Test0.
104
105 (* Test the reverse attribute *)
106 Module Test1.
107
108 Structure S := {
109 ssort : Type;
110 sstuff : ssort;
111 }.
112
113 #[reversible=no] Coercion ssort : S >-> Sortclass.
114
115 Definition test2 (s : S) := sstuff s.
116
117 Canonical Structure S_nat := {| ssort := nat; sstuff := 0; |}.
118 Fail Check test2 (nat : Type).
119
120 End Test1.
121
122 (* Test the reverse attribute *)
123 Module Test1'.
124
125 Structure S := {
126 ssort : Type;
127 sstuff : ssort;
128 }.
129
130 Coercion ssort : S >-> Sortclass.
131
132 Definition test2 (s : S) := sstuff s.
133
134 Canonical Structure S_nat := {| ssort := nat; sstuff := 0; |}.
135 Fail Check test2 (nat : Type).
136
137 End Test1'.
138
139 (* Test the reverse attribute *)
140 Module Test2.
141
142 Structure S := {
143 #[reversible=no] ssort :> Type;
144 sstuff : ssort;
145 }.
146
147 Definition test2 (s : S) := sstuff s.
148
149 Canonical Structure S_nat := {| ssort := nat; sstuff := 0; |}.
150 Fail Check test2 (nat : Type).
151
152 End Test2.
153
154 (* Test the reverse attribute *)
155 Module Test3.
156
157 Structure S := {
158 #[reversible=no] ssort :> Type;
159 sstuff : ssort;
160 }.
161
162 Definition test2 (s : S) := sstuff s.
163
164 Canonical Structure S_nat := {| ssort := nat; sstuff := 0; |}.
165
166 #[reversible] Coercion ssort.
167
168 Check test2 (nat : Type).
169
170 End Test3.
171
172 (* Test the reverse attribute *)
173 Module Test4.
174
175 Structure S := {
176 ssort :> Type;
177 sstuff : ssort;
178 }.
179
180 Definition test2 (s : S) := sstuff s.
181
182 Canonical Structure S_nat := {| ssort := nat; sstuff := 0; |}.
183
184 #[reversible=no] Coercion ssort.
185
186 Fail Check test2 (nat : Type).
187
188 End Test4.