Fixpoint fold1 (A B: Type) (f: B -> A -> B) (m: t A) (v: B) {struct m} : B :=
match m with
| Leaf => v
| Node l None r =>
let v1 := fold1 f l v in
fold1 f r v1
| Node l (Some x) r =>
let v1 := fold1 f l v in
let v2 := f v1 x in
fold1 f r v2
end.

Lemma fold1_xelements:
forall (A B: Type) (f: B -> A -> B) m i v l,
List.fold_left (fun a p => f a (snd p)) l (fold1 f m v) =
List.fold_left (fun a p => f a (snd p)) (xelements m i l) v.