Hypothesis eqAdec: EqDec A eqA.
Program Definition Equal_dec (m1 m2: T.t A) : { m1 === m2 } + { m1 =/= m2 } :=
match T.beq (fun a1 a2 => proj_sumbool (a1 == a2)) m1 m2 with
| true => left _
| false => right _
end.
Next Obligation.
rename Heq_anonymous into B.
symmetry in B. rewrite T.beq_correct in B.
red; intros. generalize (B x).
destruct (T.get x m1); destruct (T.get x m2); auto.
intros. eapply proj_sumbool_true; eauto.
Qed.
Next Obligation.
assert (T.beq (fun a1 a2 => proj_sumbool (a1 == a2)) m1 m2 = true).
apply T.beq_correct; intros.
generalize (H x).
destruct (T.get x m1); destruct (T.get x m2); try tauto.
intros. apply proj_sumbool_is_true; auto.
unfold equiv, complement in H0. congruence.
Qed.
Instance Equal_EqDec : EqDec (T.t A) Equal := Equal_dec.
End EXTENSIONAL_EQUALITY.
(** Creating a tree from a list of (key, value) pairs. *)
Section OF_LIST.
Variable A: Type.
Let f := fun (m: T.t A) (k_v: T.elt * A) => T.set (fst k_v) (snd k_v) m.
Definition of_list (l: list (T.elt * A)) : T.t A :=
List.fold_left f l (T.empty _).

Lemma of_list_dom:
forall l k, In k (map fst l) -> exists v, T.get k (of_list l) = Some v.