Section Fold.
Variables A B : Type.
Variable f : key -> A -> B -> B.
Fixpoint xfoldi (m : t A) (v : B) (i : key) :=
match m with
| Leaf _ => v
| Node l (Some x) r =>
xfoldi r (f i x (xfoldi l v (append i 2))) (append i 3)
| Node l None r =>
xfoldi r (xfoldi l v (append i 2)) (append i 3)
end.

Lemma xfoldi_1 :
forall m v i,
xfoldi m v i = fold_left (fun a p => f (fst p) (snd p) a) (xelements m i) v.