Fixpoint permute(ls : list A)(sigma : list nat) : list A :=
    match sigma with
      | nil => nil
      | n :: sigma' => 
        match (nth_error ls n) with
          | None => nil
          | Some a => a :: (permute ls sigma')
        end
  end.

Theorem nth_error_not_None : forall (ls : list A)(n : nat), n < length ls -> nth_error ls n = None -> False.