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_length : forall (A : Set)(ls : list A)(i : nat)(a def : A), i < length ls -> length (listReplace ls i a def) = length ls.