Fixpoint getSomes(A : Type)(ls : list (option A)) :=
  match ls with
    | nil => nil
    | o :: ls' =>
      match o with
        | None => getSomes ls'
        | Some x => x :: (getSomes ls')
      end
  end.

Lemma flatten_app : forall (A : Set)(ls1 ls2 : list (list A)), flatten (ls1 ++ ls2) = flatten ls1 ++ flatten ls2.