I m playing around in Coq, trying to create a sorted list.
I just wanted a function that takes a list [1,2,3,2,4]
and would return something like Sorted [1,2,3,4]
- i.e. taking out the bad parts, but not actually sorting the entire list.
I thought I would start by defining a function lesseq
of type (m n : nat) -> option (m <= n)
, and then I could pattern match on that pretty easily. Maybe that s is a bad idea.
The crux of the issue I m having right now is that (snippet, whole function at bottom)
Fixpoint lesseq (m n : nat) : option (m <= n) :=
match m with
| 0 => match n with
| 0 => Some (le_n 0)
...
is not typechecking; it says that it s expecting an option (m <= n)
, but that Some (le_n 0)
has type option (0 <= 0)
. I don t understand, because obviously both m
and n
are zero in that context, but I ve no idea how to tell Coq that.
The entire function is:
Fixpoint lesseq (m n : nat) : option (m <= n) :=
match m with
| 0 => match n with
| 0 => Some (le_n 0)
| S n_ => None
end
| S m_ => match n with
| 0 => None
| S _ => match lesseq m_ n with
| Some x=> le_S m n x
| None => None
end
end
end.
Perhaps I m getting ahead of myself and just need to keep reading before I tackle this.