| 1 |
(* Bug #1172 *) |
| 2 |
|
| 3 |
Structure foo : Type := Foo { |
| 4 |
A : Set; Aopt := option A; unopt : Aopt -> A |
| 5 |
}. |
| 6 |
|
| 7 |
Canonical Structure unopt_nat := @Foo nat (fun _ => O). |
| 8 |
|
| 9 |
(* Granted wish #1187 *) |
| 10 |
|
| 11 |
Record Silly (X : Set) : Set := mkSilly { x : X }. |
| 12 |
Definition anotherMk := mkSilly. |
| 13 |
Definition struct := anotherMk nat 3. |
| 14 |
Canonical Structure struct. |
| 15 |
|
| 16 |
(* Intertwinning canonical structures and delta-expansion *) |
| 17 |
(* Assia's short example *) |
| 18 |
|
| 19 |
Open Scope bool_scope. |
| 20 |
|
| 21 |
Set Implicit Arguments. |
| 22 |
|
| 23 |
Structure test_struct : Type := mk_test {dom :> Type; f : dom -> dom -> bool}. |
| 24 |
|
| 25 |
Notation " x != y":= (f _ x y)(at level 10). |
| 26 |
|
| 27 |
Canonical Structure bool_test := mk_test (fun x y => x || y). |
| 28 |
|
| 29 |
Definition b := bool. |
| 30 |
|
| 31 |
Check (fun x : b => x != x). |
| 32 |
|
| 33 |
Inductive four := x0 | x1 | x2 | x3. |
| 34 |
Structure local := MKL { l : four }. |
| 35 |
|
| 36 |
Module X. |
| 37 |
Definition s0 := MKL x0. |
| 38 |
#[local] Canonical Structure s0. |
| 39 |
Check (refl_equal _ : l _ = x0). |
| 40 |
|
| 41 |
#[local] Canonical Structure s1 := MKL x1. |
| 42 |
Check (refl_equal _ : l _ = x1). |
| 43 |
|
| 44 |
Local Canonical Structure s2 := MKL x2. |
| 45 |
Check (refl_equal _ : l _ = x2). |
| 46 |
|
| 47 |
End X. |
| 48 |
Fail Check (refl_equal _ : l _ = x0). |
| 49 |
Fail Check (refl_equal _ : l _ = x1). |
| 50 |
Fail Check (refl_equal _ : l _ = x2). |
| 51 |
Check X.s0. |
| 52 |
Check X.s1. |
| 53 |
Check X.s2. |
| 54 |
|
| 55 |
Module Y. |
| 56 |
Definition s3 := MKL x3. |
| 57 |
Canonical Structure s3. |
| 58 |
Check (refl_equal _ : l _ = x3). |
| 59 |
End Y. |
| 60 |
Fail Check (refl_equal _ : l _ = x3). |
| 61 |
Fail Check s3. |
| 62 |
|
| 63 |
Module V. |
| 64 |
#[canonical] Definition s3 := MKL x3. |
| 65 |
Check (refl_equal _ : l _ = x3). |
| 66 |
End V. |
| 67 |
|
| 68 |
Module W. |
| 69 |
#[canonical, local] Definition s2' := MKL x2. |
| 70 |
Check (refl_equal _ : l _ = x2). |
| 71 |
End W. |
| 72 |
Fail Check (refl_equal _ : l _ = x2). |
| 73 |
|
| 74 |
(* Lambda keys *) |
| 75 |
Module LambdaKeys. |
| 76 |
Structure cs_lambda := { cs_lambda_key : nat -> nat }. |
| 77 |
Module L1. |
| 78 |
#[local] Canonical Structure cs_lambda_func := |
| 79 |
{| cs_lambda_key := fun x => x + 1 |}. |
| 80 |
Check (refl_equal _ : cs_lambda_key _ = fun _ => _ + _). |
| 81 |
End L1. |
| 82 |
|
| 83 |
Module L2. |
| 84 |
#[local] Canonical Structure cs_lambda_func2 := |
| 85 |
{| cs_lambda_key := fun x => 1 + x |}. |
| 86 |
Check (refl_equal _ : cs_lambda_key _ = fun x => 1 + x). |
| 87 |
End L2. |
| 88 |
|
| 89 |
Module L3. |
| 90 |
#[local] Canonical Structure cs_lambda_func3 := |
| 91 |
{| cs_lambda_key := fun x => 1 + x |}. |
| 92 |
Check (refl_equal _ : cs_lambda_key _ = Nat.add 1). |
| 93 |
End L3. |
| 94 |
|
| 95 |
Module L4. |
| 96 |
#[local] Canonical Structure cs_lambda_func4 := |
| 97 |
{| cs_lambda_key := Nat.add 1 |}. |
| 98 |
Check (refl_equal _ : cs_lambda_key _ = Nat.add 1). |
| 99 |
End L4. |
| 100 |
|
| 101 |
Module L5. |
| 102 |
#[local] Canonical Structure cs_lambda_func5 := |
| 103 |
{| cs_lambda_key := Nat.add 1 |}. |
| 104 |
Check (refl_equal _ : cs_lambda_key _ = fun x => 1 + x). |
| 105 |
End L5. |
| 106 |
End LambdaKeys. |
| 107 |
|
| 108 |
Module DepProd. |
| 109 |
Structure hello := { hello_key : Type }. |
| 110 |
Module FixedTypes. |
| 111 |
Local Canonical Structure hello_dep1 := {| hello_key := forall x : nat, x = x |}. |
| 112 |
Example ex_hello2 := let h := _ in fun f : hello_key h => (f : forall x : nat, x = x) 1. |
| 113 |
End FixedTypes. |
| 114 |
|
| 115 |
Module VariableTypes. |
| 116 |
Local Canonical Structure hello_dep2 v1 v2 := {| hello_key := forall x : list v1, x = v2 |}. |
| 117 |
Example ex_hello1 : _ -> _ = nil := |
| 118 |
let h := _ in fun f : hello_key h => (f : forall x : list _, _ = _) (@nil nat). |
| 119 |
End VariableTypes. |
| 120 |
End DepProd. |
| 121 |
|
| 122 |
|
| 123 |
(* Testing that canonical projections equipped with function type instances |
| 124 |
([forall _, _]) or default instances ([_]) can be used in places where |
| 125 |
functions/function types are expected. |
| 126 |
This feature triggers CS search in two typing cases: |
| 127 |
1. [f x : _] when [f : proj _] |
| 128 |
2. [(fun x => _) : proj _]. |
| 129 |
*) |
| 130 |
Module NoCasts. |
| 131 |
Module Basic. |
| 132 |
Structure r1 (useless_param: bool) := |
| 133 |
{ #[canonical=no] r1_pre : unit |
| 134 |
; #[canonical=yes] r1_key : Type |
| 135 |
; #[canonical=no] r1_post: nat |
| 136 |
}. |
| 137 |
Canonical Structure r1_func b : r1 b := {| r1_pre:= tt; r1_key := nat -> nat; r1_post:= 0|}. |
| 138 |
Example ex_r1_1 p := let b := _ in fun f : @r1_key p b => f 1. |
| 139 |
Example ex_r1_2 p := let b := _ in (fun x => x) : @r1_key p b. |
| 140 |
End Basic. |
| 141 |
|
| 142 |
Module Primitive. |
| 143 |
Local Set Primitive Projections. |
| 144 |
Structure r2 (useless_param: bool) := |
| 145 |
{ #[canonical=no] r2_pre : unit |
| 146 |
; #[canonical=yes] r2_key : Type |
| 147 |
; #[canonical=no] r2_post: nat; }. |
| 148 |
Canonical Structure r2_func b : r2 b := {| r2_pre:= tt; r2_key := nat -> nat; r2_post:= 0|}. |
| 149 |
Example ex_r2_1 p := let b := _ in fun f : @r2_key p b => f 1. |
| 150 |
Example ex_r2_2 p := let b := _ in (fun x => x) : @r2_key p b. |
| 151 |
End Primitive. |
| 152 |
|
| 153 |
Module UsedParameters. |
| 154 |
Structure r3 (useless_param: bool) (T : Type) := |
| 155 |
{ #[canonical=no] r3_pre : unit |
| 156 |
; #[canonical=yes] r3_key : Type |
| 157 |
; #[canonical=no] r3_post: T |
| 158 |
}. |
| 159 |
Canonical Structure r3_func b : r3 b nat := {| r3_pre:= tt; r3_key := nat -> nat; r3_post:= 0|}. |
| 160 |
Example ex_r3_1 p := let b := _ in fun f : @r3_key p _ b => f 1. |
| 161 |
Example ex_r3_2 p := let b := _ in (fun x => x) : @r3_key p _ b. |
| 162 |
End UsedParameters. |
| 163 |
|
| 164 |
Module LetBoundFieldBefore. |
| 165 |
Structure r4 (useless_param: bool) := |
| 166 |
{ #[canonical=no] r4_pre : unit |
| 167 |
; #[canonical=no] r4_let := true |
| 168 |
; #[canonical=yes] r4_key : Type |
| 169 |
; #[canonical=no] r4_post: nat; |
| 170 |
}. |
| 171 |
Canonical Structure r4_func b : r4 b := {| r4_pre:= tt; r4_key := nat -> nat; r4_post:= 0|}. |
| 172 |
Example ex_r4_1 p := let b := _ in fun f : @r4_key p b => f 1. |
| 173 |
Example ex_r4_2 p := let b := _ in (fun x => x) : @r4_key p b. |
| 174 |
End LetBoundFieldBefore. |
| 175 |
|
| 176 |
Module LetBoundFieldAfter. |
| 177 |
Structure r4 (useless_param: bool) := |
| 178 |
{ #[canonical=no] r4_pre : unit |
| 179 |
; #[canonical=yes] r4_key : Type |
| 180 |
; #[canonical=no] r4_let := true |
| 181 |
; #[canonical=no] r4_post: nat; |
| 182 |
}. |
| 183 |
Canonical Structure r4_func b : r4 b := {| r4_pre:= tt; r4_key := nat -> nat; r4_post:= 0|}. |
| 184 |
Example ex_r4_1 p := let b := _ in fun f : @r4_key p b => f 1. |
| 185 |
Example ex_r4_2 p := let b := _ in (fun x => x) : @r4_key p b. |
| 186 |
End LetBoundFieldAfter. |
| 187 |
|
| 188 |
Module Tele. |
| 189 |
Inductive tele : Type := |
| 190 |
| TeleO : tele |
| 191 |
| TeleS {X} : (X -> tele) -> tele. |
| 192 |
|
| 193 |
#[local] Set Primitive Projections. |
| 194 |
Structure tele_of := { tele_term : Type; #[canonical=no] tele_tele : tele; }. |
| 195 |
Canonical Structure tele_of_prod {X} {t : X -> tele_of} := {| tele_term := forall x, (tele_term (t x)); tele_tele := TeleS (fun x => tele_tele (t x))|}. |
| 196 |
Canonical Structure tele_of_base {T} := {| tele_term := T; tele_tele := TeleO |}. |
| 197 |
|
| 198 |
Check let t : tele_of := _ in fun f : tele_term t => (f 0). |
| 199 |
(* Was Error: Ill-typed evar instance in #12383/#14715 original version *) |
| 200 |
End Tele. |
| 201 |
|
| 202 |
End NoCasts. |
| 203 |
|
| 204 |
(* Testing that we find coherent surrounding stacks for CS problems. *) |
| 205 |
Module ExtraArgs. |
| 206 |
Structure Fun := {apply : nat -> nat}. |
| 207 |
|
| 208 |
Canonical S_Fun := {| apply := S |}. |
| 209 |
Check eq_refl : apply _ = S. |
| 210 |
Check eq_refl : apply _ 0 = S 0. |
| 211 |
|
| 212 |
Canonical generic_Fun (f : nat -> nat) := {| apply := f |}. |
| 213 |
Set Debug "unification". |
| 214 |
Set Printing All. |
| 215 |
Check fun (f : nat -> nat) => eq_refl : apply _ = f. |
| 216 |
Check fun (f : nat -> nat) => eq_refl : apply _ 0 = f 0. |
| 217 |
|
| 218 |
End ExtraArgs. |
| 219 |
|
| 220 |
(* Testing that we unfold keys that match but do not unify *) |
| 221 |
Module TestKeys. |
| 222 |
Structure Dummy (b : bool) := {T : Type}. |
| 223 |
Definition boolF := bool. |
| 224 |
Canonical Dummy_boolF : Dummy false := {| T := boolF |}. |
| 225 |
Definition boolT := boolF. |
| 226 |
Canonical Dummy_boolT : Dummy true := {| T := boolT |}. |
| 227 |
|
| 228 |
Set Debug "unification". |
| 229 |
Check eq_refl : id (@T false _) = boolT. |
| 230 |
End TestKeys. |