(******************************************************************************)
(*       Module for searching and inserting elements in a list                *)
(******************************************************************************)

Definition invariant A s r i (e : A) := onth r i = Some e /\ prefix s r.Class XFind A (s : seq A) (e : A) := {
  seq_of : seq A;
  index_of : nat;
  xfind : invariant s seq_of index_of e}.Class XFind A (s : seq A) (e : A) := {
  seq_of : seq A;
  index_of : nat;
  xfind : invariant s seq_of index_of e}.Class XFind A (s : seq A) (e : A) := {
  seq_of : seq A;
  index_of : nat;
  xfind : invariant s seq_of index_of e}.Class XFind A (s : seq A) (e : A) := {
  seq_of : seq A;
  index_of : nat;
  xfind : invariant s seq_of index_of e}.Program Instance found_struct A (x:A) t : XFind (x :: t) x := {| seq_of := (x :: t); index_of := 0|}.(* Hint Extern 1 (XFind _ _) => progress simpl : typeclass_instances. *)

Example unit_test A (x1 x2 x3 x y : A):
   (forall s e (f : XFind s e), nth x1 seq_of index_of = e -> e = x) ->
  x = x.

Lemma bla A (x : A) s (C : XFind s x) : onth seq_of index_of = Some x.