13.6 Pattern-matching and coercions
If a mismatch occurs between the expected type of a pattern and its
actual type, a coercion made from constructors is sought. If such a
coercion can be found, it is automatically inserted around the
pattern.
Example:
Coq < Inductive I : Set :=
Coq < C1 : nat -> I
Coq < | C2 : I -> I.
I is defined
I_rect is defined
I_ind is defined
I_rec is defined
Coq < Coercion C1 : nat >-> I.
C1 is now a coercion
Coq < Check [x]Cases x of (C2 O) => O | _ => O end.
[x:I]
Cases x of
(C1 _) => (0)
| (C2 i) =>
Cases i of
(C1 n) => Cases n of
0 => (0)
| (S _) => (0)
end
| (C2 _) => (0)
end
end
: I->nat