Section Count.
Variable (X : eqType).
Definition count (n : nat) (x : X) (xs : t X n) :=
fold_right (fun y c => if Dec (x = y) then S c else c) xs 0.
(* (* Test *)
End Count.
Compute let xs := [|1;2;3;4;5;6|] in
let x  := 2 in
let y  := 1 in
let i  := Fin.F1 in
Dec (x = y) + count x xs = Dec (x = xs[@i]) + count x (replace xs i y).
*)
End Count.

Lemma dupfree_nth_injective (X : Type) (n : nat) (xs : Vector.t X n) :
dupfree xs -> forall (i j : Fin.t n), xs[@i] = xs[@j] -> i = j.