Fixpoint dedup (xs : list A) : list A :=
    match xs with
    | [] => []
    | x :: xs => let tail := dedup xs in
                 if in_dec A_eq_dec x xs then
                   tail
                 else
                   x :: tail
    end.

Lemma remove_dedup_comm : forall (x : A) xs, remove A_eq_dec x (dedup xs) = dedup (remove A_eq_dec x xs).