list - Modify an element in Map -
i have defined types follows:
module smap = map.make(string) type s = { t: int fa: int list } type t = s smap.t
i write function modify
add 100
list fa
element corresponding key
. following code works:
let modify (key: string) (x: t) = let = smap.find key x in smap.add key { fa = a.fa @ [100] } (smap.remove key x)
however, removing , adding element looks redundant me... tell me if there better way directly modify it?
yes, can add it.
a map can contain key once, if add mapping key, remove previous one.
http://caml.inria.fr/pub/docs/manual-ocaml/libref/map.make.html#valadd
Comments
Post a Comment