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.

(* Specifications: *)
Lemma perm_sym l1 l2: perm l1 l2 -> perm l2 l1.
Lemma perm_cons_app a l1 l2: perm ((a:: l1) ++ l2) (l1 ++ (a:: l2)).
Lemma perm_length l1 l2: perm l1 l2 -> length l1 = length l2.
Lemma perm_in a l1 l2: perm l1 l2 -> In a l1 -> In a l2.
Lemma perm_in_inv a l1: In a l1 -> exists l2, perm l1 (a:: l2).
Lemma perm_incl_r l1 l2 l3: perm l1 l2 -> incl l1 l3 -> incl l2 l3.
Lemma perm_incl_l l1 l2 l3: perm l1 l2 -> incl l3 l1 -> incl l3 l2.
End Perm.