| 1 |
Set Primitive Projections. |
| 2 |
Record mix := { a : nat ; b : a = a ; c : nat ; d : a = c ; e : nat ; f : nat }. |
| 3 |
Ltac strip_args T ctor := |
| 4 |
lazymatch type of ctor with |
| 5 |
| context[T] |
| 6 |
=> match eval cbv beta in ctor with |
| 7 |
| ?ctor _ => strip_args T ctor |
| 8 |
| _ => ctor |
| 9 |
end |
| 10 |
end. |
| 11 |
Ltac get_ctor T := |
| 12 |
let full_ctor := constr:(ltac:(let x := fresh in intro x; econstructor; apply |
| 13 |
x) : T -> T) in |
| 14 |
let ctor := constr:(fun x : T => ltac:(let v := strip_args T (full_ctor x) in |
| 15 |
exact v)) in |
| 16 |
lazymatch ctor with |
| 17 |
| fun _ => ?ctor => ctor |
| 18 |
end. |
| 19 |
Ltac uncurry_domain f := |
| 20 |
lazymatch type of f with |
| 21 |
| forall (a : ?A) (b : @ ?B a), _ |
| 22 |
=> uncurry_domain (fun ab : { a : A & B a } => f (projT1 ab) (projT2 ab)) |
| 23 |
| _ => eval cbv beta in f |
| 24 |
end. |
| 25 |
Ltac get_of_sigma T := |
| 26 |
let ctor := get_ctor T in |
| 27 |
uncurry_domain ctor. |
| 28 |
Ltac repeat_existT := |
| 29 |
lazymatch goal with |
| 30 |
| [ |- sigT _ ] => simple refine (existT _ _ _); [ repeat_existT | shelve ] |
| 31 |
| _ => shelve |
| 32 |
end. |
| 33 |
Ltac prove_to_of_sigma_goal of_sigma := |
| 34 |
let v := fresh "v" in |
| 35 |
simple refine (exist _ _ (fun v => _ : id _ (of_sigma v) = v)); |
| 36 |
try unfold of_sigma; |
| 37 |
[ intro v; destruct v; repeat_existT |
| 38 |
| cbv beta; |
| 39 |
repeat match goal with |
| 40 |
| [ |- context[projT2 ?k] ] |
| 41 |
=> let x := fresh "x" in |
| 42 |
is_var k; |
| 43 |
destruct k as [k x]; cbn [projT1 projT2] |
| 44 |
end; |
| 45 |
unfold id; reflexivity ]. |
| 46 |
Ltac prove_to_of_sigma of_sigma := |
| 47 |
constr:( |
| 48 |
ltac:(prove_to_of_sigma_goal of_sigma) |
| 49 |
: { to_sigma : _ | forall v, id to_sigma (of_sigma v) = v }). |
| 50 |
Ltac get_to_sigma_gen of_sigma := |
| 51 |
let v := prove_to_of_sigma of_sigma in |
| 52 |
eval hnf in (proj1_sig v). |
| 53 |
Ltac get_to_sigma T := |
| 54 |
let of_sigma := get_of_sigma T in |
| 55 |
get_to_sigma_gen of_sigma. |
| 56 |
Definition to_sigma := ltac:(let v := get_to_sigma mix in exact v). |
| 57 |
(* Error: |
| 58 |
In nested Ltac calls to "get_to_sigma", "get_to_sigma_gen", |
| 59 |
"prove_to_of_sigma", |
| 60 |
"(_ : {to_sigma : _ | forall v, id to_sigma (of_sigma v) = v})" (with |
| 61 |
of_sigma:=fun |
| 62 |
ab : {_ |
| 63 |
: {_ |
| 64 |
: {ab : {_ : {a : nat & a = a} & nat} & |
| 65 |
projT1 (projT1 ab) = projT2 ab} & nat} & nat} => |
| 66 |
{| |
| 67 |
a := projT1 (projT1 (projT1 (projT1 (projT1 ab)))); |
| 68 |
b := projT2 (projT1 (projT1 (projT1 (projT1 ab)))); |
| 69 |
c := projT2 (projT1 (projT1 (projT1 ab))); |
| 70 |
d := projT2 (projT1 (projT1 ab)); |
| 71 |
e := projT2 (projT1 ab); |
| 72 |
f := projT2 ab |}) and "prove_to_of_sigma_goal", last call failed. |
| 73 |
Anomaly "Uncaught exception Not_found." Please report at |
| 74 |
http://coq.inria.fr/bugs/. |
| 75 |
frame @ file "toplevel/coqtop.ml", line 640, characters 6-22 |
| 76 |
frame @ file "list.ml", line 73, characters 12-15 |
| 77 |
frame @ file "toplevel/vernac.ml", line 344, characters 2-13 |
| 78 |
frame @ file "toplevel/vernac.ml", line 308, characters 14-75 |
| 79 |
raise @ file "lib/exninfo.ml", line 63, characters 8-15 |
| 80 |
frame @ file "lib/flags.ml", line 141, characters 19-40 |
| 81 |
raise @ file "lib/exninfo.ml", line 63, characters 8-15 |
| 82 |
frame @ file "lib/flags.ml", line 11, characters 15-18 |
| 83 |
raise @ file "lib/exninfo.ml", line 63, characters 8-15 |
| 84 |
frame @ file "toplevel/vernac.ml", line 167, characters 6-16 |
| 85 |
frame @ file "toplevel/vernac.ml", line 151, characters 26-39 |
| 86 |
frame @ file "stm/stm.ml", line 2365, characters 2-35 |
| 87 |
raise @ file "lib/exninfo.ml", line 63, characters 8-15 |
| 88 |
frame @ file "stm/stm.ml", line 2355, characters 4-48 |
| 89 |
frame @ file "stm/stm.ml", line 2321, characters 4-100 |
| 90 |
raise @ file "lib/exninfo.ml", line 63, characters 8-15 |
| 91 |
frame @ file "stm/stm.ml", line 832, characters 6-10 |
| 92 |
frame @ file "stm/stm.ml", line 2206, characters 10-32 |
| 93 |
raise @ file "lib/exninfo.ml", line 63, characters 8-15 |
| 94 |
frame @ file "stm/stm.ml", line 975, characters 8-81 |
| 95 |
raise @ file "lib/exninfo.ml", line 63, characters 8-15 |
| 96 |
frame @ file "vernac/vernacentries.ml", line 2216, characters 10-389 |
| 97 |
frame @ file "lib/flags.ml", line 141, characters 19-40 |
| 98 |
raise @ file "lib/exninfo.ml", line 63, characters 8-15 |
| 99 |
frame @ file "lib/flags.ml", line 11, characters 15-18 |
| 100 |
frame @ file "vernac/command.ml", line 150, characters 4-56 |
| 101 |
frame @ file "interp/constrintern.ml", line 2046, characters 2-73 |
| 102 |
frame @ file "pretyping/pretyping.ml", line 1194, characters 19-77 |
| 103 |
frame @ file "pretyping/pretyping.ml", line 1155, characters 8-72 |
| 104 |
frame @ file "pretyping/pretyping.ml", line 628, characters 23-65 |
| 105 |
frame @ file "plugins/ltac/tacinterp.ml", line 2095, characters 21-61 |
| 106 |
frame @ file "proofs/pfedit.ml", line 178, characters 6-22 |
| 107 |
raise @ file "lib/exninfo.ml", line 63, characters 8-15 |
| 108 |
frame @ file "proofs/pfedit.ml", line 174, characters 8-36 |
| 109 |
frame @ file "proofs/proof.ml", line 351, characters 4-30 |
| 110 |
raise @ file "lib/exninfo.ml", line 63, characters 8-15 |
| 111 |
frame @ file "engine/proofview.ml", line 1222, characters 8-12 |
| 112 |
frame @ file "plugins/ltac/tacinterp.ml", line 2020, characters 19-36 |
| 113 |
frame @ file "plugins/ltac/tacinterp.ml", line 618, characters 4-70 |
| 114 |
raise @ file "lib/exninfo.ml", line 63, characters 8-15 |
| 115 |
frame @ file "plugins/ltac/tacinterp.ml", line 214, characters 6-9 |
| 116 |
frame @ file "pretyping/pretyping.ml", line 1198, characters 19-62 |
| 117 |
frame @ file "pretyping/pretyping.ml", line 1155, characters 8-72 |
| 118 |
raise @ unknown |
| 119 |
frame @ file "pretyping/pretyping.ml", line 628, characters 23-65 |
| 120 |
frame @ file "plugins/ltac/tacinterp.ml", line 2095, characters 21-61 |
| 121 |
frame @ file "proofs/pfedit.ml", line 178, characters 6-22 |
| 122 |
raise @ file "lib/exninfo.ml", line 63, characters 8-15 |
| 123 |
frame @ file "proofs/pfedit.ml", line 174, characters 8-36 |
| 124 |
frame @ file "proofs/proof.ml", line 351, characters 4-30 |
| 125 |
raise @ file "lib/exninfo.ml", line 63, characters 8-15 |
| 126 |
*) |