Fixpoint firstIndexOf(A : Set)(eqd : eq_dec A)(ls : list A)(a : A)(def : nat) :=
  match ls with
      | nil => def
      | a' :: ls' =>
        if (eqd a a') then O else (S (firstIndexOf eqd ls' a def))
  end.

Theorem nth_firstIndexOf_if : forall (A : Set)(eqd : eq_dec A)(ls : list A) n a, nth_option ls n = Some a -> NoDup ls -> firstIndexOf eqd ls a 0 = n.