| 1 |
(* Test des definitions inductives imbriquees *) |
| 2 |
|
| 3 |
Inductive X : Set := |
| 4 |
cons1 : list X -> X. |
| 5 |
|
| 6 |
Inductive Y : Set := |
| 7 |
cons2 : list (Y * Y) -> Y. |
| 8 |
|
| 9 |
(* Test inductive types with local definitions (arity) *) |
| 10 |
|
| 11 |
Inductive eq1 : forall A:Type, let B:=A in A -> Prop := |
| 12 |
refl1 : eq1 True I. |
| 13 |
|
| 14 |
Check |
| 15 |
fun (P : forall A : Type, let B := A in A -> Type) (f : P True I) (A : Type) => |
| 16 |
let B := A in |
| 17 |
fun (a : A) (e : eq1 A a) => |
| 18 |
match e in (@eq1 A0 B0 a0) return (P A0 a0) with |
| 19 |
| refl1 => f |
| 20 |
end. |
| 21 |
|
| 22 |
Inductive eq2 (A:Type) (a:A) |
| 23 |
: forall B C:Type, let D:=(A*B*C)%type in D -> Prop := |
| 24 |
refl2 : eq2 A a unit bool (a,tt,true). |
| 25 |
|
| 26 |
(* Check inductive types with local definitions (parameters) *) |
| 27 |
|
| 28 |
Inductive A (C D : Prop) (E:=C) (F:=D) (x y : E -> F) : E -> Set := |
| 29 |
I : forall z : E, A C D x y z. |
| 30 |
|
| 31 |
Check |
| 32 |
(fun C D : Prop => |
| 33 |
let E := C in |
| 34 |
let F := D in |
| 35 |
fun (x y : E -> F) (P : forall c : C, A C D x y c -> Type) |
| 36 |
(f : forall z : C, P z (I C D x y z)) (y0 : C) |
| 37 |
(a : A C D x y y0) => |
| 38 |
match a as a0 in (A _ _ _ _ y1) return (P y1 a0) with |
| 39 |
| I _ _ _ _ x0 => f x0 |
| 40 |
end). |
| 41 |
|
| 42 |
Record B (C D : Set) (E:=C) (F:=D) (x y : E -> F) : Set := {p : C; q : E}. |
| 43 |
|
| 44 |
Check |
| 45 |
(fun C D : Set => |
| 46 |
let E := C in |
| 47 |
let F := D in |
| 48 |
fun (x y : E -> F) (P : B C D x y -> Type) |
| 49 |
(f : forall p0 q0 : C, P (Build_B C D x y p0 q0)) |
| 50 |
(b : B C D x y) => |
| 51 |
match b as b0 return (P b0) with |
| 52 |
| Build_B _ _ _ _ x0 x1 => f x0 x1 |
| 53 |
end). |
| 54 |
|
| 55 |
(* Check inductive types with local definitions (constructors) *) |
| 56 |
|
| 57 |
Inductive I1 : Set := C1 (_:I1) (_:=0). |
| 58 |
|
| 59 |
Check (fun x:I1 => |
| 60 |
match x with |
| 61 |
| C1 i n => (i,n) |
| 62 |
end). |
| 63 |
|
| 64 |
(* Check implicit parameters of inductive types (submitted by Pierre |
| 65 |
Casteran and also implicit in BZ#338) *) |
| 66 |
|
| 67 |
Set Implicit Arguments. |
| 68 |
Unset Strict Implicit. |
| 69 |
|
| 70 |
CoInductive LList (A : Set) : Set := |
| 71 |
| LNil : LList A |
| 72 |
| LCons : A -> LList A -> LList A. |
| 73 |
|
| 74 |
Arguments LNil {A}. |
| 75 |
|
| 76 |
Inductive Finite (A : Set) : LList A -> Prop := |
| 77 |
| Finite_LNil : Finite LNil |
| 78 |
| Finite_LCons : |
| 79 |
forall (a : A) (l : LList A), Finite l -> Finite (LCons a l). |
| 80 |
|
| 81 |
(* Check positivity modulo reduction (cf bug BZ#983) *) |
| 82 |
|
| 83 |
Record P:Type := {PA:Set; PB:Set}. |
| 84 |
|
| 85 |
Definition F (p:P) := (PA p) -> (PB p). |
| 86 |
|
| 87 |
Inductive I_F:Set := c : (F (Build_P nat I_F)) -> I_F. |
| 88 |
|
| 89 |
(* Check that test for binders capturing implicit arguments is not stronger |
| 90 |
than needed (problem raised by Cedric Auger) *) |
| 91 |
|
| 92 |
Set Implicit Arguments. |
| 93 |
Inductive bool_comp2 (b: bool): bool -> Prop := |
| 94 |
| Opp2: forall q, (match b return Prop with |
| 95 |
| true => match q return Prop with |
| 96 |
true => False | |
| 97 |
false => True end |
| 98 |
| false => match q return Prop with |
| 99 |
true => True | |
| 100 |
false => False end end) -> bool_comp2 b q. |
| 101 |
|
| 102 |
(* This one is still to be made acceptable... |
| 103 |
|
| 104 |
Set Implicit Arguments. |
| 105 |
Inductive I A : A->Prop := C a : (forall A, A) -> I a. |
| 106 |
|
| 107 |
*) |
| 108 |
|
| 109 |
(* Test recursively non-uniform parameters (was formerly in params_ind.v) *) |
| 110 |
|
| 111 |
Inductive list (A : Set) : Set := |
| 112 |
| nil : list A |
| 113 |
| cons : A -> list (A -> A) -> list A. |
| 114 |
|
| 115 |
(* Check inference of evars in arity using information from constructors *) |
| 116 |
|
| 117 |
Inductive foo1 : forall p, Prop := cc1 : foo1 0. |
| 118 |
|
| 119 |
(* Check cross inference of evars from constructors *) |
| 120 |
|
| 121 |
Inductive foo2 : forall p, Prop := cc2 : forall q, foo2 q | cc3 : foo2 0. |
| 122 |
|
| 123 |
(* An example with reduction removing an occurrence of the inductive type in one of its argument *) |
| 124 |
|
| 125 |
Inductive IND1 (A:Type) := CONS1 : IND1 ((fun x => A) IND1). |
| 126 |
|
| 127 |
(* These types were considered as ill-formed before March 2015, while they |
| 128 |
could be accepted considering that the type IND1 above was accepted *) |
| 129 |
|
| 130 |
Inductive IND2 (A:Type) (T:=fun _ : Type->Type => A) := CONS2 : IND2 A -> IND2 (T IND2). |
| 131 |
|
| 132 |
Inductive IND3 (A:Type) (T:=fun _ : Type->Type => A) := CONS3 : IND3 (T IND3) -> IND3 A. |
| 133 |
|
| 134 |
Inductive IND4 (A:Type) := CONS4 : IND4 ((fun x => A) IND4) -> IND4 A. |
| 135 |
|
| 136 |
(* This type was ok before March 2015 *) |
| 137 |
|
| 138 |
Inductive IND5 (A : Type) (T := A) : Type := CONS5 : IND5 ((fun _ => A) 0) -> IND5 A. |
| 139 |
|
| 140 |
(* An example of nested positivity which was rejected by the kernel |
| 141 |
before 24 March 2015 (even with Unset Elimination Schemes to avoid |
| 142 |
the _rect bug) due to the wrong computation of non-recursively |
| 143 |
uniform parameters in list' *) |
| 144 |
|
| 145 |
Inductive list' (A:Type) (B:=A) := |
| 146 |
| nil' : list' A |
| 147 |
| cons' : A -> list' B -> list' A. |
| 148 |
|
| 149 |
Inductive tree := node : list' tree -> tree. |
| 150 |
|
| 151 |
(* This type was raising an anomaly when building the _rect scheme, |
| 152 |
because of a bug in Inductiveops.get_arity in the presence of |
| 153 |
let-ins and recursively non-uniform parameters. *) |
| 154 |
|
| 155 |
Inductive L (A:Type) (T:=A) : Type := C : L nat -> L A. |
| 156 |
|
| 157 |
(* This type was raising an anomaly when building the _rect scheme, |
| 158 |
because of a wrong computation of the number of non-recursively |
| 159 |
uniform parameters when conversion is needed, leading the example to |
| 160 |
hit the Inductiveops.get_arity bug mentioned above (see #3491) *) |
| 161 |
|
| 162 |
Inductive IND6 (A:Type) (T:=A) := CONS6 : IND6 T -> IND6 A. |
| 163 |
|
| 164 |
|
| 165 |
Module TemplateProp. |
| 166 |
|
| 167 |
(** Check lowering of a template universe polymorphic inductive to Prop *) |
| 168 |
|
| 169 |
Inductive Foo (A : Type) : Type := foo : A -> Foo A. |
| 170 |
|
| 171 |
Check Foo True : Prop. |
| 172 |
|
| 173 |
End TemplateProp. |
| 174 |
|
| 175 |
Module PolyNoLowerProp. |
| 176 |
|
| 177 |
(** Check lowering of a general universe polymorphic inductive to Prop is _failing_ *) |
| 178 |
|
| 179 |
Polymorphic Inductive Foo (A : Type) : Type := foo : A -> Foo A. |
| 180 |
|
| 181 |
Fail Check Foo True : Prop. |
| 182 |
|
| 183 |
End PolyNoLowerProp. |
| 184 |
|
| 185 |
(* Test building of elimination scheme with noth let-ins and |
| 186 |
non-recursively uniform parameters *) |
| 187 |
|
| 188 |
Module NonRecLetIn. |
| 189 |
|
| 190 |
Unset Implicit Arguments. |
| 191 |
|
| 192 |
Inductive Ind (b:=2) (a:nat) (c:=1) : Type := |
| 193 |
| Base : Ind a |
| 194 |
| Rec : Ind (S a) -> Ind a. |
| 195 |
|
| 196 |
Check Ind_rect (fun n (b:Ind n) => b = b) |
| 197 |
(fun n => eq_refl) |
| 198 |
(fun n b c => f_equal (Rec n) eq_refl) 0 (Rec 0 (Base 1)). |
| 199 |
|
| 200 |
End NonRecLetIn. |
| 201 |
|
| 202 |
(* Test treatment of let-in in the definition of Records *) |
| 203 |
(* Should fail with "Sort expected" *) |
| 204 |
|
| 205 |
Fail Inductive foo (T : Type) : let T := Type in T := |
| 206 |
{ r : forall x : T, x = x }. |
| 207 |
|
| 208 |
Module Discharge. |
| 209 |
(* discharge test *) |
| 210 |
Section S. |
| 211 |
Let x := Prop. |
| 212 |
Inductive foo : x := bla : foo. |
| 213 |
End S. |
| 214 |
Check bla:foo. |
| 215 |
|
| 216 |
Section S. |
| 217 |
Variables (A:Type). |
| 218 |
(* ensure params are scanned for needed section variables even with template arity *) |
| 219 |
#[universes(template)] Inductive bar (d:A) := . |
| 220 |
End S. |
| 221 |
Check @bar nat 0. |
| 222 |
End Discharge. |