Section dedup.
Variable A : Type.
Hypothesis A_eq_dec : forall x y : A, {x = y} + {x <> y}.
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.
Proof using.
intros. simpl in *.
break_match.
+ auto.
+ exfalso. intuition.
Qed.
Proof using.
induction xs; intros; simpl in *.
- intuition.
- break_if; intuition; subst; simpl; auto.
Qed.
Proof using.
intros.
induction xs; simpl; repeat (break_match; simpl);
auto using f_equal2; try discriminate.
+ exfalso. apply n. apply in_app_iff. apply in_app_or in i. intuition.
+ exfalso. apply n. apply in_app_or in i. intuition.
* simpl in *. intuition. congruence.
Qed.

Lemma dedup_app : forall (xs ys : list A),
(forall x y, In x xs -> In y ys -> x <> y) ->
dedup (xs ++ ys) = dedup xs ++ dedup ys.