Definition elt := M.elt.Definition elt_eq := M.elt_eq.(* A set of equivalence classes over elt is represented by a map m.
   M.get a m = Some a' means that a is in the same class as a'.
   M.get a m = None means that a is the canonical representative
     for its equivalence class. *)

(* The ordering over elt induced by such a map.
   repr_order m a a' iff M.get a' m = Some a.
   This ordering must be well founded. *)

Definition order (m: M.t elt) (a a': elt) : Prop :=
  M.get a' m = Some a.Record unionfind : Type := mk { m: M.t elt; mwf: well_founded (order m) }.Record unionfind : Type := mk { m: M.t elt; mwf: well_founded (order m) }.Record unionfind : Type := mk { m: M.t elt; mwf: well_founded (order m) }.Record unionfind : Type := mk { m: M.t elt; mwf: well_founded (order m) }.Definition t := unionfind.Definition getlink (m: M.t elt) (a: elt) : {a' | M.get a m = Some a'} + {M.get a m = None}.Definition F_repr (a: elt) (rec: forall b, order uf.(m) b a -> elt) : elt :=
  match getlink uf.(m) a with
  | inleft (exist a' P) => rec a' P
  | inright _ => a
  end.Definition repr (a: elt) : elt := Fix uf.(mwf) (fun _ => elt) F_repr a.

Lemma repr_some_diff: forall a a', M.get a uf.(m) = Some a' -> a <> repr a'.