Fixpoint assoc (l : list (K * V)) (k : K) : option V :=
    match l with
      | [] => None
      | (k', v) :: l' =>
        if K_eq_dec k k' then
          Some v
        else
          assoc l' k
    end.Definition assoc_default (l : list (K * V)) (k : K) (default : V) : V :=
    match (assoc l k) with
      | Some x => x
      | None => default
    end.Fixpoint assoc_set (l : list (K * V)) (k : K) (v : V) : list (K * V) :=
    match l with
      | [] => [(k, v)]
      | (k', v') :: l' =>
        if K_eq_dec k k' then
          (k, v) :: l'
        else
          (k', v') :: (assoc_set l' k v)
    end.Fixpoint assoc_del (l : list (K * V)) (k : K) : list (K * V) :=
    match l with
      | [] => []
      | (k', v') :: l' =>
        if K_eq_dec k k' then
          assoc_del l' k
        else
          (k', v') :: (assoc_del l' k)
    end.

(* Specifications: *)
Lemma get_set_same : forall k v l, assoc (assoc_set l k v) k = Some v.
Lemma get_set_same' : forall k k' v l, k = k' -> assoc (assoc_set l k v) k' = Some v.
Lemma get_set_diff : forall k k' v l, k <> k' -> assoc (assoc_set l k v) k' = assoc l k'.
Lemma not_in_assoc : forall k l, ~ In k (map (@fst _ _) l) -> assoc l k = None.
Lemma get_del_same : forall k l, assoc (assoc_del l k) k = None.
Lemma get_del_diff : forall k k' l, k <> k' -> assoc (assoc_del l k') k = assoc l k.
Lemma get_set_diff_default : forall (k k' : K) (v : V) l d, k <> k' -> assoc_default (assoc_set l k v) k' d = assoc_default l k' d.
Lemma get_set_same_default : forall (k : K) (v : V) l d, assoc_default (assoc_set l k v) k d = v.
Lemma assoc_assoc_default: forall l k (v : V) d, assoc l k = Some v -> assoc_default l k d = v.
Lemma assoc_assoc_default_missing: forall (l : list (K * V)) k d, assoc l k = None -> assoc_default l k d = d.
Lemma assoc_set_same : forall (l : list (K * V)) k v, assoc l k = Some v -> assoc_set l k v = l.
Lemma assoc_default_assoc_set : forall l (k : K) (v : V) d, assoc_default (assoc_set l k v) k d = v.
Lemma assoc_set_assoc_set_same : forall l (k : K) (v : V) v', assoc_set (assoc_set l k v) k v' = assoc_set l k v'.