Record dict (K V : Type) := Dict { dict_elems : list (K * V) }.
Arguments Dict {K V} _.
Arguments dict_elems {K V} _.
Fixpoint lookup_falist {K V : Type} `{Ord K} (v : V) (k : K) (kvs : list (K * V)) :=
match kvs with
| [] => v
| (k' , v') :: kvs' =>
match ord_dec k k' with
| Lt => v
| Eq => v'
| Gt => lookup_falist v k kvs'
end
end.
Fixpoint update_falist {K V : Type} `{Ord K} (k : K) (v : V) (kvs : list (K * V)) : list (K * V) :=
match kvs with
| [] => [ (k , v) ]
| (k' , v') :: kvs' =>
match ord_dec k k' with
| Lt => (k , v) :: (k' , v') :: kvs'
| Eq => (k , v) :: kvs'
| Gt => (k' , v') :: update_falist k v kvs'
end
end.
Definition lookup_dict {K V : Type} `{Ord K} (v : V) (k : K) (kvs : dict K V) :=
lookup_falist v k (dict_elems kvs).
Definition update_dict {K V : Type} `{Ord K} (k : K) (v : V) (kvs : dict K V) : dict K V :=
Dict (update_falist k v (dict_elems kvs)).

Lemma lookup_update_diffid {K V} `{Ord K} : forall (k k' : K) (v v_def : V) m,
k <> k' ->
lookup_dict v_def k (update_dict k' v m) =
lookup_dict v_def k m.