I am following the book Computational Type Theory and Interactive Theorem Proving with Coq, and one of the exercises is for me to write of term of type:
forall (p:bool -> Prop) (x:bool), (x = true -> p true) -> (x = false -> p false) -> p x
I tried the obvious:
Fail Definition L7 : forall (p:bool -> Prop) (x:bool), (x = true -> p true) -> (x = false -> p false) -> p x :=
fun (p:bool -> Prop) =>
fun (x:bool) =>
fun (tt:x = true -> p true) =>
fun (ff:x = false -> p false) =>
match x with
| true => tt (eq_refl true)
| false => ff (eq_refl false)
end.
and the less obvious:
Definition bool_dec : forall (x:bool), x = true \/ x = false :=
fun (x:bool) =>
match x with
| true => or_introl (eq_refl true)
| false => or_intror (eq_refl false)
end.
Fail Definition L8 : forall (p:bool -> Prop) (x:bool), (x = true -> p true) -> (x = false -> p false) -> p x :=
fun (p:bool -> Prop) =>
fun (x:bool) =>
fun (tt:x = true -> p true) =>
fun (ff:x = false -> p false) =>
match bool_dec x with
| or_introl p => tt p
| or_intror p => ff p
end.
I know there is going to be a trick match ... in ... return ... or some convoy pattern business, leading to a duh moment on my part, but I have been spending an hour on this and would like to move on. Can anyone take me out of my misery?