Consider the following example:
Definition cast {A : Set} (B : Set) (prf : A = B) (x : A) : B.
rewrite prf in x.
refine x.
Defined.
Lemma castLemma0 {A : Set} : forall (x : A) prf, cast A prf x = x.
Proof.
intros.
compute.
???
After the compute step, we are left with the following context and subgoal
A : Set
x : A
prf : A = A
______________________________________(1/1)
match prf in (_ = y) return y with
| eq_refl => x
end = x
Clearly the left hand side and right hand side are equal. But I am not sure how to get rid of the annoying 'match' clause on the left hand side. In particular, trying to destruct prf yields the following error
Abstracting over the terms "A" and "prf"
leads to a term
fun (A0 : Set) (prf0 : A0 = A0) =>
match prf0 in (_ = y) return y with
| eq_refl => x
end = x which is ill-typed.
Reason is: In pattern-matching on term
"prf0" the branch for constructor
"eq_refl" has type "A" which should be
"A0".
Is there a way to get rid of this match clause?