| 1 |
(* Testing the behavior of implicit arguments *) |
| 2 |
|
| 3 |
(* Implicit on section variables *) |
| 4 |
|
| 5 |
Set Implicit Arguments. |
| 6 |
Unset Strict Implicit. |
| 7 |
|
| 8 |
(* Example submitted by David Nowak *) |
| 9 |
|
| 10 |
Section Spec. |
| 11 |
Variable A : Set. |
| 12 |
Variable op : forall A : Set, A -> A -> Set. |
| 13 |
Infix "#" := op (at level 70). |
| 14 |
Check (forall x : A, x # x). |
| 15 |
|
| 16 |
(* Example submitted by Christine *) |
| 17 |
|
| 18 |
Record stack : Type := |
| 19 |
{type : Set; elt : type; empty : type -> bool; proof : empty elt = true}. |
| 20 |
|
| 21 |
Check |
| 22 |
(forall (type : Set) (elt : type) (empty : type -> bool), |
| 23 |
empty elt = true -> stack). |
| 24 |
|
| 25 |
(* Nested sections and manual/automatic implicit arguments *) |
| 26 |
|
| 27 |
Variable op' : forall A : Set, A -> A -> Set. |
| 28 |
Variable op'' : forall A : Set, A -> A -> Set. |
| 29 |
|
| 30 |
Section B. |
| 31 |
|
| 32 |
Definition eq1 := fun (A:Type) (x y:A) => x=y. |
| 33 |
Definition eq2 := fun (A:Type) (x y:A) => x=y. |
| 34 |
Definition eq3 := fun (A:Type) (x y:A) => x=y. |
| 35 |
|
| 36 |
Arguments op' : clear implicits. |
| 37 |
Global Arguments op'' : clear implicits. |
| 38 |
|
| 39 |
Arguments eq2 : clear implicits. |
| 40 |
Global Arguments eq3 : clear implicits. |
| 41 |
|
| 42 |
Check (op 0 0). |
| 43 |
Check (op' nat 0 0). |
| 44 |
Check (op'' nat 0 0). |
| 45 |
Check (eq1 0 0). |
| 46 |
Check (eq2 nat 0 0). |
| 47 |
Check (eq3 nat 0 0). |
| 48 |
|
| 49 |
End B. |
| 50 |
|
| 51 |
Check (op 0 0). |
| 52 |
Check (op' 0 0). |
| 53 |
Check (op'' nat 0 0). |
| 54 |
Check (eq1 0 0). |
| 55 |
Check (eq2 0 0). |
| 56 |
Check (eq3 nat 0 0). |
| 57 |
|
| 58 |
End Spec. |
| 59 |
|
| 60 |
Check (eq1 0 0). |
| 61 |
Check (eq2 0 0). |
| 62 |
Check (eq3 nat 0 0). |
| 63 |
|
| 64 |
(* Example submitted by Frédéric (interesting in v8 syntax) *) |
| 65 |
|
| 66 |
Parameter f : nat -> nat * nat. |
| 67 |
Notation lhs := fst. |
| 68 |
Check (fun x => fst (f x)). |
| 69 |
Check (fun x => fst (f x)). |
| 70 |
Notation rhs := snd. |
| 71 |
Check (fun x => snd (f x)). |
| 72 |
Check (fun x => @ rhs _ _ (f x)). |
| 73 |
|
| 74 |
(* Implicit arguments in fixpoints and inductive declarations *) |
| 75 |
|
| 76 |
Fixpoint g n := match n with O => true | S n => g n end. |
| 77 |
|
| 78 |
Inductive P n : nat -> Prop := c : P n n. |
| 79 |
|
| 80 |
(* Avoid evars in the computation of implicit arguments (cf r9827) *) |
| 81 |
|
| 82 |
Fixpoint plus n m {struct n} := |
| 83 |
match n with |
| 84 |
| 0 => m |
| 85 |
| S p => S (plus p m) |
| 86 |
end. |
| 87 |
|
| 88 |
(* Check multiple implicit arguments signatures *) |
| 89 |
|
| 90 |
Arguments eq_refl {A x}, {A}. |
| 91 |
|
| 92 |
Check eq_refl : 0 = 0. |
| 93 |
|
| 94 |
(* Check that notations preserve implicit (since 8.3) *) |
| 95 |
|
| 96 |
Parameter p : forall A, A -> forall n, n = 0 -> True. |
| 97 |
Arguments p [A] _ [n]. |
| 98 |
Notation Q := (p 0). |
| 99 |
Check Q eq_refl. |
| 100 |
|
| 101 |
(* Check implicits with Context *) |
| 102 |
|
| 103 |
Section C. |
| 104 |
Context {A:Set}. |
| 105 |
Definition h (a:A) := a. |
| 106 |
End C. |
| 107 |
Check h 0. |
| 108 |
|
| 109 |
(* Check implicit arguments in arity of inductive types. The three |
| 110 |
following examples used to fail before r13671 *) |
| 111 |
|
| 112 |
Inductive I {A} (a:A) : forall {n:nat}, Prop := |
| 113 |
| C : I a (n:=0). |
| 114 |
|
| 115 |
Inductive I' [A] (a:A) : forall [n:nat], n =0 -> Prop := |
| 116 |
| C' : I' a eq_refl. |
| 117 |
|
| 118 |
Inductive I2 (x:=0) : Prop := |
| 119 |
| C2 {p:nat} : p = 0 -> I2 |
| 120 |
| C2' [p:nat] : p = 0 -> I2. |
| 121 |
Check C2' eq_refl. |
| 122 |
|
| 123 |
Inductive I3 {A} (x:=0) (a:A) : forall {n:nat}, Prop := |
| 124 |
| C3 : I3 a (n:=0). |
| 125 |
|
| 126 |
(* Check global implicit declaration over ref not in section *) |
| 127 |
|
| 128 |
Section D. Global Arguments eq [A] _ _. End D. |
| 129 |
|
| 130 |
(* Check local manual implicit arguments *) |
| 131 |
(* Gives a warning and make the second x anonymous *) |
| 132 |
(* Isn't the name "arg_1" a bit fragile though? *) |
| 133 |
|
| 134 |
Check fun f : forall {x:nat} {x:bool} (x:unit), unit => f (x:=1) (arg_2:=true) tt. |
| 135 |
|
| 136 |
(* Check the existence of a shadowing warning *) |
| 137 |
|
| 138 |
Set Warnings "+syntax". |
| 139 |
Fail Check fun f : forall {x:nat} {x:bool} (x:unit), unit => f (x:=1) (arg_2:=true) tt. |
| 140 |
Set Warnings "syntax". |
| 141 |
|
| 142 |
(* Test failure when implicit arguments are mentioned in subterms |
| 143 |
which are not types of variables *) |
| 144 |
|
| 145 |
Set Warnings "+syntax". |
| 146 |
Fail Check (id (forall {a}, a)). |
| 147 |
Set Warnings "syntax". |
| 148 |
|
| 149 |
(* Miscellaneous tests *) |
| 150 |
|
| 151 |
Check let f := fun {x:nat} y => y=true in f false. |
| 152 |
Check let f := fun [x:nat] y => y=true in f false. |
| 153 |
|
| 154 |
(* Isn't the name "arg_1" a bit fragile, here? *) |
| 155 |
|
| 156 |
Check fun f : forall {_:nat}, nat => f (arg_1:=0). |
| 157 |
|
| 158 |
(* This test was wrongly warning/failing at some time *) |
| 159 |
|
| 160 |
Set Warnings "+syntax". |
| 161 |
Check id (fun x => let f c {a} (b:a=a) := b in f true (eq_refl 0)). |
| 162 |
Set Warnings "syntax". |
| 163 |
|
| 164 |
|
| 165 |
Axiom eq0le0 : forall (n : nat) (x : n = 0), n <= 0. |
| 166 |
Parameter eq0le0' : forall (n : nat) {x : n = 0}, n <= 0. |
| 167 |
Axiom eq0le0'' : forall (n : nat) {x : n = 0}, n <= 0. |
| 168 |
Definition eq0le0''' : forall (n : nat) {x : n = 0}, n <= 0. Admitted. |
| 169 |
Fail Axiom eq0le0'''' : forall [n : nat] {x : n = 0}, n <= 0. |
| 170 |
|
| 171 |
Module TestUnnamedImplicit. |
| 172 |
|
| 173 |
Axiom foo : forall A, A -> A. |
| 174 |
|
| 175 |
Arguments foo {A} {_}. |
| 176 |
Check foo (arg_2:=true) : bool. |
| 177 |
Check foo (1:=true) : bool. |
| 178 |
Check foo : bool. |
| 179 |
|
| 180 |
Arguments foo {A} {x}. |
| 181 |
Check foo (x:=true) : bool. |
| 182 |
|
| 183 |
Axiom bar : forall A, A -> nat -> forall B, B -> A * B. |
| 184 |
Arguments bar {A} {x} _ {B} {y}. |
| 185 |
Check bar (1:=true) 0 (3:=false). |
| 186 |
|
| 187 |
End TestUnnamedImplicit. |
| 188 |
|
| 189 |
Module NotationAppliedConstantMultipleImplicit. |
| 190 |
|
| 191 |
Axiom f : nat -> nat -> nat -> nat. |
| 192 |
Arguments f {_} _ _, {_ _} _. |
| 193 |
Notation "#" := (@f 0). |
| 194 |
Check # 0 : nat. |
| 195 |
|
| 196 |
End NotationAppliedConstantMultipleImplicit. |