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.

Theorem listReplace_getSomes_Permutation : forall (A : Set) l1 l2 n2 (y : A), nth n2 l1 None = None -> Permutation (getSomes l1) l2 -> Permutation (getSomes (listReplace l1 n2 (Some y) None)) (y :: l2).