Proof using.
intros c; apply ulist_unique_key.
unfold restrict_code in |- *.
replace
(map (fst (B:=_))
(map (fun x : A * nat => (fst x, find_code eqA_dec (fst x) c))
(frequency_list eqA_dec m))) with
(map (fst (B:=_)) (frequency_list eqA_dec m)).
apply unique_key_ulist; auto.
elim (frequency_list eqA_dec m); simpl in |- *; auto with datatypes.
intros a l H; apply f_equal2 with (f := cons (A:=A)); auto.
Qed.

(* Doing the restriction does not change the codes *)
Theorem restrict_code_in :
forall (a : A) (c : code A),
In a m -> find_code eqA_dec a c = find_code eqA_dec a (restrict_code m c).