Fixpoint compare_list {A: Type} (f: A -> A -> comparison) (xl yl : list A)
  : comparison :=
  match xl , yl with
  | x :: xl', y :: yl' => match f x y with
                          | Eq => compare_list f xl' yl'
                          | c => c
                          end
  | nil , _ :: _ => Lt
  | _ :: _ , nil => Gt
  | nil, nil => Eq
  end.

(* Specifications: *)
Lemma list_cspec: forall {A} (cmp: A -> A -> comparison) (cmp_spec: CompSpec' cmp), CompSpec' (compare_list cmp).
Lemma comp_antisym: forall {A} (cmp: A -> A -> comparison) (cspec: CompSpec' cmp), forall x y, Lt = cmp x y <-> Gt = cmp y x.
Lemma NoDup_rsort_uniq: forall {A} (cmp: A -> A -> comparison) (cspec: CompSpec' cmp), forall l, NoDup (rsort_uniq cmp l).
Lemma Forall_sortu: forall {A} (f: A -> Prop) (cmp: A -> A -> comparison) l, Forall f l -> Forall f (rsort_uniq cmp l).
Lemma rsort_uniq_in: forall {A} (R: A -> A -> comparison) (EQ: forall a b, (a=b) <-> (Eq = R a b)) x l, List.In x (rsort_uniq R l) <-> List.In x l.