Views using dependent pattern-matching
The user can write a view function to implement this. First one needs to write
a discriminator for the inductive type, indicating which cases are to be merged together:
One can derive an inductive representing the view of three as cone and the two other
ctwo and cthree cases lumbed together.
Inductive three_two_view : three → Set :=
| three_one : three_two_view cone
| three_other c : discr_three c → three_two_view c.
| three_one : three_two_view cone
| three_other c : discr_three c → three_two_view c.
This view is obviously inhabited for any element in three.
Equations three_viewc c : three_two_view c :=
three_viewc cone := three_one;
three_viewc c := three_other c I.
three_viewc cone := three_one;
three_viewc c := three_other c I.
Using a with clause one can pattern-match on the view argument to
do case splitting on three using only two cases. In each branch,
one can see that the three variable is determined by the view pattern.
Equations onthree (c : three) : three :=
onthree c with three_viewc c :=
onthree ?(cone) three_one := cone;
onthree ?(c) (three_other c Hc) := c.
onthree c with three_viewc c :=
onthree ?(cone) three_one := cone;
onthree ?(c) (three_other c Hc) := c.
This page has been generated by coqdoc