(** Comparison functions. *)
Require Char.
(** Total order on strings. *)
Fixpoint compare (x y : t) : comparison :=
match x, y with
| [], [] => Eq
| [], _ => Lt
| _, [] => Gt
| x :: xs, y :: ys =>
match Char.compare x y with
| Eq => compare xs ys
| c => c
end
end.
induction x as [|a x HI]; destruct y as [|b y]; simpl; try congruence.
case_eq (Char.compare a b); simpl; try congruence.
now intros Hab Hxy; rewrite (Char.compare_implies_eq _ _ Hab); rewrite (HI _ Hxy).
Qed.
intro x; induction x; simpl; trivial.
now rewrite Char.compare_same_is_eq; rewrite IHx.
Qed.
(** Test if two strings are equal. *)
Definition eqb (x y : t) : bool :=
match compare x y with
| Eq => true
| _ => false
end.
intros x y; unfold eqb; case_eq (compare x y); try congruence.
now intros; apply compare_implies_eq.
Qed.

Lemma eqb_same_is_eq : forall (x : t), eqb x x = true.