| 1 |
Polymorphic Cumulative Inductive T1 := t1 : T1. |
| 2 |
Fail Monomorphic Cumulative Inductive T2 := t2 : T2. |
| 3 |
|
| 4 |
Polymorphic Cumulative Record R1 := { r1 : T1 }. |
| 5 |
Fail Monomorphic Cumulative Inductive R2 := {r2 : T1}. |
| 6 |
|
| 7 |
Set Universe Polymorphism. |
| 8 |
Set Polymorphic Inductive Cumulativity. |
| 9 |
Set Printing Universes. |
| 10 |
|
| 11 |
Inductive List (A: Type) := nil | cons : A -> List A -> List A. |
| 12 |
|
| 13 |
Definition LiftL@{k i j|k <= i, k <= j} {A:Type@{k}} : List@{i} A -> List@{j} A := fun x => x. |
| 14 |
|
| 15 |
Lemma LiftL_Lem A (l : List A) : l = LiftL l. |
| 16 |
Proof. reflexivity. Qed. |
| 17 |
|
| 18 |
Inductive Tp := tp : Type -> Tp. |
| 19 |
|
| 20 |
Definition LiftTp@{i j|i <= j} : Tp@{i} -> Tp@{j} := fun x => x. |
| 21 |
|
| 22 |
Fail Definition LowerTp@{i j|j < i} : Tp@{i} -> Tp@{j} := fun x => x. |
| 23 |
|
| 24 |
Record Tp' := { tp' : Tp }. |
| 25 |
|
| 26 |
Definition CTp := Tp. |
| 27 |
(* here we have to reduce a constant to infer the correct subtyping. *) |
| 28 |
Record Tp''@{+u} := { tp'' : CTp@{u} }. |
| 29 |
|
| 30 |
Definition LiftTp'@{i j|i <= j} : Tp'@{i} -> Tp'@{j} := fun x => x. |
| 31 |
Definition LiftTp''@{i j|i <= j} : Tp''@{i} -> Tp''@{j} := fun x => x. |
| 32 |
|
| 33 |
Lemma LiftC_Lem (t : Tp) : LiftTp t = t. |
| 34 |
Proof. reflexivity. Qed. |
| 35 |
|
| 36 |
Section subtyping_test. |
| 37 |
Universe i j. |
| 38 |
Constraint i < j. |
| 39 |
|
| 40 |
Inductive TP2 := tp2 : Type@{i} -> Type@{j} -> TP2. |
| 41 |
|
| 42 |
End subtyping_test. |
| 43 |
|
| 44 |
Record A : Type := { a :> Type; }. |
| 45 |
|
| 46 |
Record B (X : A) : Type := { b : X; }. |
| 47 |
|
| 48 |
NonCumulative Inductive NCList (A: Type) |
| 49 |
:= ncnil | nccons : A -> NCList A -> NCList A. |
| 50 |
|
| 51 |
Fail Definition LiftNCL@{k i j|k <= i, k <= j} {A:Type@{k}} |
| 52 |
: NCList@{i} A -> NCList@{j} A := fun x => x. |
| 53 |
|
| 54 |
Inductive eq@{i} {A : Type@{i}} (x : A) : A -> Type@{i} := eq_refl : eq x x. |
| 55 |
|
| 56 |
Definition funext_type@{a b e} (A : Type@{a}) (B : A -> Type@{b}) |
| 57 |
:= forall f g : (forall a, B a), |
| 58 |
(forall x, eq@{e} (f x) (g x)) |
| 59 |
-> eq@{e} f g. |
| 60 |
|
| 61 |
Section down. |
| 62 |
Universes a b e e'. |
| 63 |
Constraint e' < e. |
| 64 |
Lemma funext_down {A B} |
| 65 |
: @funext_type@{a b e} A B -> @funext_type@{a b e'} A B. |
| 66 |
Proof. |
| 67 |
intros H f g Hfg. exact (H f g Hfg). |
| 68 |
Defined. |
| 69 |
End down. |
| 70 |
|
| 71 |
Record Arrow@{i j} := { arrow : Type@{i} -> Type@{j} }. |
| 72 |
|
| 73 |
Fail Definition arrow_lift@{i i' j j' | i' < i, j < j'} |
| 74 |
: Arrow@{i j} -> Arrow@{i' j'} |
| 75 |
:= fun x => x. |
| 76 |
|
| 77 |
Definition arrow_lift@{i i' j j' | i' = i, j <= j'} |
| 78 |
: Arrow@{i j} -> Arrow@{i' j'} |
| 79 |
:= fun x => x. |
| 80 |
|
| 81 |
Inductive Mut1 A := |
| 82 |
| Base1 : Type -> Mut1 A |
| 83 |
| Node1 : (A -> Mut2 A) -> Mut1 A |
| 84 |
with Mut2 A := |
| 85 |
| Base2 : Type -> Mut2 A |
| 86 |
| Node2 : Mut1 A -> Mut2 A. |
| 87 |
|
| 88 |
(* If we don't reduce T while inferring cumulativity for the |
| 89 |
constructor we will see a Rel and believe i is irrelevant. *) |
| 90 |
Inductive withparams@{i j} (T:=Type@{i}:Type@{j}) := mkwithparams : T -> withparams. |
| 91 |
|
| 92 |
Definition withparams_co@{i i' j|i < i', i' < j} : withparams@{i j} -> withparams@{i' j} |
| 93 |
:= fun x => x. |
| 94 |
|
| 95 |
Fail Definition withparams_not_irr@{i i' j|i' < i, i' < j} : withparams@{i j} -> withparams@{i' j} |
| 96 |
:= fun x => x. |
| 97 |
|
| 98 |
(** Cumulative constructors *) |
| 99 |
|
| 100 |
|
| 101 |
Record twotys@{u v w} : Type@{w} := |
| 102 |
twoconstr { fstty : Type@{u}; sndty : Type@{v} }. |
| 103 |
|
| 104 |
Monomorphic Universes i j k l. |
| 105 |
|
| 106 |
Monomorphic Constraint i < j. |
| 107 |
Monomorphic Constraint j < k. |
| 108 |
Monomorphic Constraint k < l. |
| 109 |
|
| 110 |
Parameter Tyi : Type@{i}. |
| 111 |
|
| 112 |
Definition checkcumul := |
| 113 |
eq_refl _ : @eq twotys@{k k l} (twoconstr@{i j k} Tyi Tyi) (twoconstr@{j i k} Tyi Tyi). |
| 114 |
|
| 115 |
(* They can only be compared at the highest type *) |
| 116 |
Fail Definition checkcumul' := |
| 117 |
eq_refl _ : @eq twotys@{i k l} (twoconstr@{i j k} Tyi Tyi) (twoconstr@{j i k} Tyi Tyi). |
| 118 |
|
| 119 |
(* An inductive type with an irrelevant universe *) |
| 120 |
Inductive foo@{i} : Type@{i} := mkfoo { }. |
| 121 |
|
| 122 |
Definition bar := foo. |
| 123 |
|
| 124 |
(* The universe on mkfoo is flexible and should be unified with i. *) |
| 125 |
Definition foo1@{i} : foo@{i} := let x := mkfoo in x. (* fast path for conversion *) |
| 126 |
Definition foo2@{i} : bar@{i} := let x := mkfoo in x. (* must reduce *) |
| 127 |
|
| 128 |
(* Rigid universes however should not be unified unnecessarily. *) |
| 129 |
Definition foo3@{i j|} : foo@{i} := let x := mkfoo@{j} in x. |
| 130 |
Definition foo4@{i j|} : bar@{i} := let x := mkfoo@{j} in x. |
| 131 |
|
| 132 |
(* Constructors for an inductive with indices *) |
| 133 |
Module WithIndex. |
| 134 |
Inductive foo@{i} : (Prop -> Prop) -> Prop := mkfoo: foo (fun x => x). |
| 135 |
|
| 136 |
Monomorphic Universes i j. |
| 137 |
Monomorphic Constraint i < j. |
| 138 |
Definition bar : eq mkfoo@{i} mkfoo@{j} := eq_refl _. |
| 139 |
End WithIndex. |
| 140 |
|
| 141 |
Module CumulApp. |
| 142 |
|
| 143 |
(* i is covariant here, and we have one parameter *) |
| 144 |
Inductive foo@{i} (A : nat) : Type@{i+1} := mkfoo (B : Type@{i}). |
| 145 |
|
| 146 |
Definition bar@{i j|i<=j} := fun x : foo@{i} 0 => x : foo@{j} 0. |
| 147 |
|
| 148 |
End CumulApp. |
| 149 |
|
| 150 |
Module InSection. |
| 151 |
|
| 152 |
Section S. |
| 153 |
Polymorphic Cumulative Structure T : Type := {sort : Type}. |
| 154 |
Polymorphic Universe u. |
| 155 |
Polymorphic Cumulative Structure T' : Type := {sort' : Type -> Type@{u}}. |
| 156 |
Polymorphic Cumulative Structure T'' : Type := {sort'' : Type}. |
| 157 |
End S. |
| 158 |
|
| 159 |
Check T@{Set}. |
| 160 |
Check T'@{Set Set}. |
| 161 |
|
| 162 |
(* T'' expects two universes, that is also u; do we really want it? *) |
| 163 |
Fail Check T''@{Set}. |
| 164 |
|
| 165 |
End InSection. |