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}.
Canonical union_form i j k ts1 ts2 f1 f2 :=
Form (@union_pf i j k ts1 ts2 f1 f2).
(* check if reached empty *)

Lemma empty_pf i : axiom i i [::] (empty_tag Unit).