Fixpoint fin_compare_compat (n : nat) : forall (x y : fin n), Compare fin_lt eq x y :=
match n with
| 0 => fun x y : fin 0 => match x with end
| S n' => fun x y : fin (S n') =>
match x, y with
| Some x', Some y' =>
match fin_compare_compat n' x' y' with
| LT pf => LT (fin_lt_Some_intro pf)
| EQ pf => EQ (f_equal _ pf)
| GT pf => GT (fin_lt_Some_intro pf)
end
| Some x', None => GT (None_lt_Some n' x')
| None, Some y' => LT (None_lt_Some n' y')
| None, None => EQ eq_refl
end
end.
Module Type NatValue.
Parameter n : nat.
End NatValue.
Module fin_OT_compat (Import N : NatValue) <: UsualOrderedType.
Definition t := fin n.
Definition eq := @eq (fin n).
Definition lt := @fin_lt n.
Definition eq_refl := @eq_refl (fin n).
Definition eq_sym := @eq_sym (fin n).
Definition eq_trans := @eq_trans (fin n).
Definition lt_trans := @fin_lt_trans n.
Definition lt_not_eq := @fin_lt_not_eq n.
Definition compare := fin_compare_compat n.
Definition eq_dec := fin_eq_dec n.
End fin_OT_compat.

Lemma CompSpec_Lt :
forall n' (x' y' : fin n'),
CompSpec eq fin_lt x' y' Lt ->
fin_lt x' y'.