(** [partition] *)

    Fixpoint partition (l:list A) : list A * list A :=
      match l with
      | [] => ([], [])
      | x :: tl => let (g,d) := partition tl in
                   if f x then (x::g,d) else (g,x::d)
      end.

Lemma filter_map_swap A B f g l : filter f (@map A B g l) = @map A B g (filter (fun a => f (g a)) l).