End Invalid.
(********************************)
(********************************)
(* Canonical structure programs *)
(********************************)
(********************************)
(* first a helper program for searching and inserting in a list *)
Section XFind.
Variable A : Type.
Structure tagged_elem := XTag {xuntag :> A}.
(* Local Coercion untag : tagged_elem >-> A. *)
Definition extend_tag := XTag.
Definition recurse_tag := extend_tag.
Canonical found_tag x := recurse_tag x.
(* Main structure:                                                  *)
(* - xs1 : input sequence                                           *)
(* - xs2 : output sequence; if pivot is found, then xs2 = xs1, else *)
(*   xs2 = pivot :: xs1                                             *)
(* - i : output index of pivot in xs2                               *)
Definition axiom xs1 xs2 i (pivot : tagged_elem) :=
onth xs2 i = Some (xuntag pivot) /\ prefix xs1 xs2.
Structure xfind (xs1 xs2 : seq A) (i : nat) :=
Form {pivot :> tagged_elem; _ : axiom xs1 xs2 i pivot}.

(* Specifications: *)
(* found the elements *)
Lemma found_pf x t : axiom (x :: t) (x :: t) 0 (found_tag x).
Canonical union_form i j k ts1 ts2 f1 f2 :=
Form (@union_pf i j k ts1 ts2 f1 f2).