let rec upd_assoc (key: 'key) (data: 'data) (map: ('key * 'data) list)
  : ('key * 'data) list =
    begin match map with
    | [] -> [ (key, data) ]
    | (k, _) :: map1 when k = key -> (k, data) :: map1
    | (k, d) :: map1 -> (k, d) :: upd_assoc key data map1
    end