(* Lexicographic comparison *)
Fixpoint list_compare (T : Type) (cmp : T -> T -> comparison)
(l1 l2 : list T) :=
match l1, l2 with
|   nil,   nil => Eq
|   nil,   _   => Lt
|     _,   nil => Gt
| a::l1, b::l2 => match cmp a b with
|  Eq => list_compare T cmp l1 l2
| res => res
end
end.

Lemma list_compare_eq T cmp l1 l2 :
(forall c1 c2, match cmp c1 c2 with Eq => c1 = c2 | _ => True end) ->
match list_compare T cmp l1 l2 with Eq => l1 = l2 | _ => True end.