| 1 |
Ltac force_clear := |
| 2 |
clear; |
| 3 |
repeat match goal with |
| 4 |
| [ H : _ |- _ ] => clear H |
| 5 |
| [ H := _ |- _ ] => clearbody H |
| 6 |
end. |
| 7 |
|
| 8 |
Class abstract_term {T} (x : T) := by_abstract_term : T. |
| 9 |
#[export] Hint Extern 0 (@abstract_term ?T ?x) => force_clear; change T; abstract (exact x) : typeclass_instances. |
| 10 |
|
| 11 |
Goal True. |
| 12 |
(* These work: *) |
| 13 |
let term := constr:(I) in |
| 14 |
let T := type of term in |
| 15 |
let x := constr:((_ : abstract_term term) : T) in |
| 16 |
pose x. |
| 17 |
let term := constr:(I) in |
| 18 |
let T := type of term in |
| 19 |
let x := constr:((_ : abstract_term term) : T) in |
| 20 |
let x := (eval cbv iota in (let v : T := x in v)) in |
| 21 |
pose x. |
| 22 |
let term := constr:(I) in |
| 23 |
let T := type of term in |
| 24 |
let x := constr:((_ : abstract_term term) : T) in |
| 25 |
let x := match constr:(Set) with ?y => constr:(y) end in |
| 26 |
pose x. |
| 27 |
(* This fails with an error: *) |
| 28 |
let term := constr:(I) in |
| 29 |
let T := type of term in |
| 30 |
let x := constr:((_ : abstract_term term) : T) in |
| 31 |
let x := match constr:(x) with ?y => constr:(y) end in |
| 32 |
pose x. (* The command has indeed failed with message: |
| 33 |
Error: Variable y should be bound to a term. *) |
| 34 |
(* And the rest fail with Anomaly: Uncaught exception Not_found. Please report. *) |
| 35 |
let term := constr:(I) in |
| 36 |
let T := type of term in |
| 37 |
let x := constr:((_ : abstract_term term) : T) in |
| 38 |
let x := match constr:(x) with ?y => y end in |
| 39 |
pose x. |
| 40 |
let term := constr:(I) in |
| 41 |
let T := type of term in |
| 42 |
let x := constr:((_ : abstract_term term) : T) in |
| 43 |
let x := (eval cbv iota in x) in |
| 44 |
pose x. |
| 45 |
let term := constr:(I) in |
| 46 |
let T := type of term in |
| 47 |
let x := constr:((_ : abstract_term term) : T) in |
| 48 |
let x := type of x in |
| 49 |
pose x. (* should succeed *) |
| 50 |
let term := constr:(I) in |
| 51 |
let T := type of term in |
| 52 |
let x := constr:(_ : abstract_term term) in |
| 53 |
let x := type of x in |
| 54 |
pose x. (* should succeed *) |
| 55 |
|
| 56 |
(*Apparently what [cbv iota] doesn't see can't hurt it, and [pose] is perfectly happy with abstracted lemmas only some of the time. |
| 57 |
|
| 58 |
Even stranger, consider:*) |
| 59 |
let term := constr:(I) in |
| 60 |
let T := type of term in |
| 61 |
let x := constr:((_ : abstract_term term) : T) in |
| 62 |
let y := (eval cbv iota in (let v : T := x in v)) in |
| 63 |
pose y; |
| 64 |
let x' := fresh "x'" in |
| 65 |
pose x as x'. |
| 66 |
let x := (eval cbv delta [x'] in x') in |
| 67 |
pose x; |
| 68 |
let z := (eval cbv iota in x) in |
| 69 |
pose z. |
| 70 |
|
| 71 |
(*This works fine. But if I change the period to a semicolon, I get:*) |
| 72 |
|
| 73 |
let term := constr:(I) in |
| 74 |
let T := type of term in |
| 75 |
let x := constr:((_ : abstract_term term) : T) in |
| 76 |
let y := (eval cbv iota in (let v : T := x in v)) in |
| 77 |
pose y; |
| 78 |
let x' := fresh "x'" in |
| 79 |
pose x as x'; |
| 80 |
let x := (eval cbv delta [x'] in x') in |
| 81 |
pose x. (* Anomaly: Uncaught exception Not_found. Please report. *) |
| 82 |
(* should succeed *) |
| 83 |
(*and if I use the second one instead of [pose x] (note that using [idtac] works fine), I get:*) |
| 84 |
|
| 85 |
let term := constr:(I) in |
| 86 |
let T := type of term in |
| 87 |
let x := constr:((_ : abstract_term term) : T) in |
| 88 |
let y := (eval cbv iota in (let v : T := x in v)) in |
| 89 |
pose y; |
| 90 |
let x' := fresh "x'" in |
| 91 |
pose x as x'; |
| 92 |
let x := (eval cbv delta [x'] in x') in |
| 93 |
let z := (eval cbv iota in x) in (* Error: Variable x should be bound to a term. *) |
| 94 |
idtac. (* should succeed *) |
| 95 |
exact I. |
| 96 |
Qed. |