Fixpoint dmap2 (a : A) (l1: list A) (l2: list B) {struct l2}: list C :=
match l1, l2 with
a1::l3, b1 :: l4 => g a1 b1 :: dmap2 a l3 l4
|    nil, b1 :: l4 =>  g a b1 :: dmap2 a nil l4
| _, _ => nil
end.
End Fold2.
Arguments dhead[A].
Arguments fold2[A B C].
Arguments map2[A B C].
Arguments dmap2[A B C].
Section Perm.
Variable A: Type.
Inductive perm: list A -> list A -> Prop :=
perm_id: forall l, perm l l
| perm_swap: forall a b l,  perm (a::b::l) (b::a::l)
| perm_skip: forall a l1 l2,  perm l1 l2 -> perm (a::l1) (a::l2)
| perm_trans: forall l1 l2 l3, perm l1 l2 -> perm l2 l3 -> perm l1 l3.

Lemma perm_length l1 l2: perm l1 l2 -> length l1 = length l2.