Debian Codegraph @

test-suite/output/UnivBinders.v

raw
1 (* -*- coq-prog-args: ("-top" "UnivBinders"); -*- *)
2
3 Set Universe Polymorphism.
4 Set Printing Universes.
5 (* Unset Strict Universe Declaration. *)
6
7 (* universe binders on inductive types and record projections *)
8 Inductive Empty@{uu} : Type@{uu} := .
9 Print Empty.
10
11 Set Primitive Projections.
12 Record PWrap@{uu} (A:Type@{uu}) := pwrap { punwrap : A }.
13 Print PWrap.
14 Print punwrap.
15
16 Unset Primitive Projections.
17 Record RWrap@{uu} (A:Type@{uu}) := rwrap { runwrap : A }.
18 Print RWrap.
19 Print runwrap.
20
21 (* universe binders also go on the constants for operational typeclasses. *)
22 Class Wrap@{uu} (A:Type@{uu}) := wrap : A.
23 Print Wrap.
24 Print wrap.
25
26 (* Instance in lemma mode used to ignore the binders. *)
27 #[global]
28 Instance bar@{uu} : Wrap@{uu} Set. Proof. exact nat. Qed.
29 Print bar.
30
31 Unset Strict Universe Declaration.
32 (* The universes in the binder come first, then the extra universes in
33 order of appearance. *)
34 Definition foo@{uu +} := Type -> Type@{v} -> Type@{uu}.
35 Print foo.
36
37 Check Type@{i} -> Type@{j}.
38
39 Eval cbv in Type@{i} -> Type@{j}.
40
41 Set Strict Universe Declaration.
42
43 (* Binders even work with monomorphic definitions! *)
44 Monomorphic Definition mono@{uu} := Type@{uu}.
45 Print mono.
46 Check mono.
47 Check Type@{mono.uu}.
48
49 Module mono.
50 Fail Monomorphic Universe uu.
51 Monomorphic Universe MONOU.
52
53 Monomorphic Definition monomono := Type@{MONOU}.
54 Check monomono.
55
56 Monomorphic Inductive monoind@{i} : Type@{i} := .
57 Monomorphic Record monorecord@{i} : Type@{i} := mkmonorecord {}.
58 End mono.
59 Check mono.monomono. (* qualified MONOU *)
60 Import mono.
61 Check monomono. (* unqualified MONOU *)
62 Check mono. (* still qualified mono.u *)
63
64 Monomorphic Constraint Set < UnivBinders.mono.uu.
65
66 Module mono2.
67 Monomorphic Universe uu.
68 End mono2.
69
70 Fail Monomorphic Definition mono2@{uu} := Type@{uu}.
71
72 Module SecLet.
73 Unset Universe Polymorphism.
74 Section fooS.
75 (* Fail Let foo@{} := Type@{uu}. (* doesn't parse: Let foo@{...} doesn't exist *) *)
76
77 Unset Strict Universe Declaration.
78 (* the names used disappear, and fresh names are generated instead of exposing raw ints *)
79 Let tt : Type@{uu} := Type@{v}.
80 #[clearbody] Let ff : Type@{uu}. Proof. exact Type@{v}. Defined.
81 Definition bobmorane := tt -> ff.
82 End fooS.
83 Print bobmorane.
84 End SecLet.
85
86 (* fun x x => foo is nonsense with local binders *)
87 Fail Definition fo@{uu uu} := Type@{uu}.
88
89 (* Using local binders for printing. *)
90 Print foo@{E M N}.
91 (* Underscores discard the name if there's one. *)
92 Print foo@{_ _ _}.
93 (* Can use a name for multiple universes *)
94 Print foo@{u u IMPORTANT}.
95
96 (* Also works for inductives and records. *)
97 Print Empty@{E}.
98 Print PWrap@{E}.
99
100 (* Also works for About. *)
101 About punwrap@{K}.
102
103 (* Instance length check. *)
104 Fail Print foo@{E}.
105 Fail Print mono@{E}.
106
107 (* Not everything can be printed with custom universe names. *)
108 Fail Print Stdlib.Init.Logic@{E}.
109
110 (* Nice error when constraints are impossible. *)
111 Monomorphic Universes gU gV. Monomorphic Constraint gU < gV.
112 Fail Lemma foo'@{u v|u < gU, gV < v, v < u} : nat.
113
114 Section SomeSec.
115 Universe uu.
116 Definition insec@{v} := Type@{uu} -> Type@{v}.
117 Print insec.
118
119 Inductive insecind@{k} := inseccstr : Type@{k} -> insecind.
120 Print insecind.
121 End SomeSec.
122 Print insec.
123 Print insecind.
124
125 Section SomeSec2.
126 Universe u.
127 Definition insec2@{} := Prop.
128 End SomeSec2.
129 Print insec2.
130
131 Module SomeMod.
132 Definition inmod@{uu} := Type@{uu}.
133 Print inmod.
134 End SomeMod.
135 Print SomeMod.inmod.
136 Import SomeMod.
137 Print inmod.
138
139 Module Type SomeTyp. Definition inmod := Type. End SomeTyp.
140 Module SomeFunct (In : SomeTyp).
141 Definition infunct@{uu v} := In.inmod@{uu} -> Type@{v}.
142 End SomeFunct.
143 Module Applied := SomeFunct(SomeMod).
144 Print Applied.infunct.
145
146 (* Multi-axiom declaration
147
148 In polymorphic mode the domain Type gets separate universes for the
149 different axioms, but all axioms have to declare all universes. In
150 monomorphic mode they also get separate universes. *)
151 Axiom axfoo@{i+} axbar : Type -> Type@{i}.
152 Monomorphic Axiom axfoo'@{i+} axbar' : Type -> Type@{i}.
153
154 About axfoo. About axbar. About axfoo'. About axbar'.
155
156 Print axfoo. Print axbar. Print axfoo'. Print axbar'.
157
158 Fail Axiom failfoo failbar@{i} : Type.
159
160 (* Notation interaction *)
161 Module Notas.
162 Unset Universe Polymorphism.
163 Module Import M. Universe i. End M.
164
165 Polymorphic Definition foo@{i} := Type@{M.i} -> Type@{i}.
166 Print foo. (* must not print Type@{i} -> Type@{i} *)
167
168 End Notas.
169
170 Module NoAutoNames.
171 Monomorphic Universe u0.
172
173 (* The anonymous universe doesn't get a name (names are only
174 invented at the end of a definition/inductive) so no need to
175 qualify u0. *)
176 Check (Type@{u0} -> Type).
177
178 End NoAutoNames.
179
180 (* Universe binders survive through compilation, sections and modules. *)
181 Require TestSuite.bind_univs.
182 Print bind_univs.mono.
183 Print bind_univs.poly.
184
185 Module MutualTypes.
186
187 Inductive MutualR1 (A:Type) := { p1 : MutualR2 A }
188 with MutualR2 (A:Type) := { p2 : MutualR1 A }.
189 Print MutualR1.
190
191 Inductive MutualI1 (A:Type) := C1 (p1 : MutualI2 A)
192 with MutualI2 (A:Type) := C2 (p2 : MutualI1 A).
193 Print MutualI1.
194
195 CoInductive MutualR1' (A:Type) := { p1' : MutualR2' A }
196 with MutualR2' (A:Type) := { p2' : MutualR1' A }.
197 Print MutualR1'.
198
199 CoInductive MutualI1' (A:Type) := C1' (p1 : MutualI2' A)
200 with MutualI2' (A:Type) := C2' (p2 : MutualI1' A).
201 Print MutualI2'.
202
203 End MutualTypes.
204
205 Module Inconsistency.
206
207 Set Universe Polymorphism.
208 Definition g@{a b} := Type@{a} : Type@{b}.
209 Fail Definition h@{a} := g@{a a}.
210
211 End Inconsistency.
212
213 Module PartialTemplate.
214
215 Set Implicit Arguments.
216 Unset Elimination Schemes.
217 Unset Universe Polymorphism.
218
219 Inductive JMeq (A:Type) (x:A) : forall B:Type, B -> Prop :=
220 JMeq_refl : JMeq x x.
221
222 About JMeq.
223
224 End PartialTemplate.
225
226 Module Collision.
227 Unset Universe Polymorphism.
228
229 Module x.
230 Universe u0.
231 Definition a := Type@{u0}.
232 End x.
233
234 Fail Definition x@{u0} := Type@{u0}.
235 Definition x := Type.
236
237 Goal True.
238 Fail
239 let a := eval cbv in x.a in
240 let b := eval cbv in x in
241 constr_eq_strict a b.
242
243 let a := eval cbv in Type@{x.u1} in
244 let b := eval cbv in x in
245 constr_eq_strict a b.
246 Abort.
247 End Collision.
248
249 Module Schemes.
250 Check eq_rect.
251 End Schemes.
252
253 Module SortPoly.
254
255 Set Warnings "deprecated-sort-poly-syntax".
256
257 Definition idu@{u} (A:Type@{u}) (a:A) := a.
258
259 Definition id@{s|u|} (A:Type@{s|u}) (a:A) := a.
260
261 Definition id2@{s;u} (A:Type@{s;u}) (a:A) := a.
262
263 Definition id3@{s ; u | Set < u} (A:Type@{s;u}) (a:A) := a.
264
265 Check id@{Prop|Set}.
266 Check id@{SProp;Set}.
267 Print id3.
268
269 End SortPoly.