Module AutoYes. Inductive Box (A:Type) : Type := box : A -> Box A.
About Box.
(* This checks that Box is template poly, see module No for how it fails *)
Universe i j. Constraint i < j. Definition j_lebox (A:Type@{j}) := Box A. Definition box_lti A := Box A : Type@{i}.
End AutoYes.
Module AutoNo. UnsetAuto Template Polymorphism. Inductive Box (A:Type) : Type := box : A -> Box A.
About Box.
Universe i j. Constraint i < j. Definition j_lebox (A:Type@{j}) := Box A.
Fail Definition box_lti A := Box A : Type@{i}.
End AutoNo.
Module Yes.
#[universes(template)] Inductive Box@{i} (A:Type@{i}) : Type@{i} := box : A -> Box A.
About Box.
Universe i j. Constraint i < j. Definition j_lebox (A:Type@{j}) := Box A. Definition box_lti A := Box A : Type@{i}.
End Yes.
Module No.
#[universes(template=no)] Inductive Box (A:Type) : Type := box : A -> Box A.
About Box.
Universe i j. Constraint i < j. Definition j_lebox (A:Type@{j}) := Box A.
Fail Definition box_lti A := Box A : Type@{i}. End No.
Module ExplicitTemplate.
#[universes(template)] Inductive identity@{i} (A : Type@{i}) (a : A) : A -> Type@{i} := id_refl (_:A) : identity A a a.
(* There used to be a weird interaction of template polymorphism and inductive types which fall in Prop due to kernel sort inference. This inductive is template polymorphic, but the universe annotation Type@{i} was ignored by the kernel which infered it lived in any universe and thus put it in Prop. This is not the case anymore since return sort inference has been removed
from the kernel. Now the universe annotation is respected by the kernel. *)
Fail Check (identity Type nat nat : Prop). Check (identity True I I : Prop). Check identity nat 0 0 : Set.
Fail Check identity Type nat nat : Set. Check identity Type nat nat : Type. End ExplicitTemplate.
Module ExplicitTemplate2.
#[universes(template)] Inductive identity@{i} (A : Type@{i}) (a : A) : A -> Type@{i} := id_refl : identity A a a. (* we generate fresh qualities for A and the conclusion, and they end up unrelated therefore the conclusion quality has no binders,
we can't make it a template poly quality and instead collapse to Type *)
Fail Check (identity Type nat nat : Prop).
Fail Check (identity True I I : Prop). Check identity nat 0 0 : Set.
Fail Check identity Type nat nat : Set. Check identity Type nat nat : Type. End ExplicitTemplate2.
Polymorphic Definition f@{i} : Type@{i} := nat.
Polymorphic Definition baz@{i} : Type@{i} -> Type@{i} := fun x => x.
Section Foo.
Universe u.
Context (A : Type@{u}).
Inductive Bar :=
| bar : A -> Bar.
Set Universe Minimization ToSet. Inductive Baz :=
| cbaz : A -> baz Baz -> Baz.
(* 2 constructors, at least in Set *) Inductive Bazset@{v} :=
| cbaz1 : A -> baz@{v} Bazset -> Bazset
| cbaz2 : Bazset.
Evalcompute in ltac:(let T := type of A in exact T).
Inductive Foo : Type :=
| foo : A -> f -> Foo.
End Foo.
Set Printing Universes. (* Cannot fall back to Prop or Set anymore as baz is no longer template-polymorphic *)
Fail Check Bar True : Prop.
Fail Check Bar nat : Set.
About Baz.
Check cbaz True I.
(** Neither can it be Set *)
Fail Check Baz nat : Set.
(** No longer possible for Baz' which contains a type in Set *)
Fail Check Baz' True : Prop.
Fail Check Baz' nat : Set.
(** We can force the universe instantiated in [baz Bazset] to be [u], so Bazset lives in max(Set, u). *)
Constraint u = Bazset.v. (** As u is global it is already > Set, so: *) Definition bazsetex@{i | i < u} : Type@{u} := Bazset Type@{i}.
(* Bazset is closed for universes u = u0, cannot be instantiated with Prop *) Definition bazseetpar (X : Type@{u}) : Type@{u} := Bazset X.
Definition foo_proj {A} (f : Foo A) : nat := match f with foo _ _ n => n end.
Definition ex : Foo True := foo _ I 0. Check foo_proj ex.
(** See failure/Template.v for a test of the unsafe Unset Template Check usage *)
Module AutoTemplateTest. Set Warnings "+auto-template". Section Foo.
Universe u'.
Context (A : Type@{u'}).
(* Not failing as Bar cannot be made template polymorphic at all *) Inductive Bar :=
| bar : A -> Bar. End Foo. End AutoTemplateTest.
Module TestTemplateAttribute. Section Foo.
Universe u.
Context (A : Type@{u}).
Set Warnings "+no-template-universe".
(* Failing as Bar cannot be made template polymorphic at all *)
Fail #[universes(template)] Inductive Bar :=
| bar : A -> Bar.
End Foo. End TestTemplateAttribute.
Module SharingWithoutSection. Inductive Foo A (S:= fun _ => Set : ltac:(let ty := type of A in exact ty))
:= foo : S A -> Foo A.
Fail Check Foo True : Prop. End SharingWithoutSection.
Module OkNotCovered. (* Here it happens that box is safe but we don't see it *) Section S.
Universe u. Variable A : Type@{u}. Inductive box (A:Type@{u}) := Box : A -> box A. Definition B := Set : Type@{u}. End S.
Fail Check box True : Prop. End OkNotCovered.
Fail Check option True : Prop. Check option nat : Set.
Fail Check option Set : Set. Check option Set : Type. End ExplicitOption.
Module QvarInCtor. (* this could be sort polymorphic: Record Foo@{q|u v|} (A:Type@{q|u}) : Type@{q|max(u,v+1)} := { foo1 : A; foo2 : forall P : Type@{q|v}, P }.
but qvar "q" (and univ "v") cannot be template poly due to appearing in the constructor (even if we generalized template poly to allow conversion-irrelevant appearances, this one isn't irrelevant)
so we need to collapse q := Type and can be template poly on u *)
Record Foo A := { foo1 : A ; foo2 : forall P, P }.
(* u cannot be template poly (it's global) but we could be template sort polymorphic *) Inductive foo (A:Type@{u}) (B:Type@{u}) C := pair (_:A) (_:B) (_:C).
Fail Check foo True True True : Prop. (* maybe will be allowed someday *)
Fail Check foo nat nat nat : Set. (* must not be allowed *) End SemiPoly.
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.