Hello!
I’m coming from elm and with this language, we can do:
myDict : Dict String Int
myDict = Dict.fromList [("answer", 42), ("age", 10)]
(see https://package.elm-lang.org/packages/elm/core/latest/Dict#fromList )
a.k.a convert an association list to a dictionary (“Map” in the OCaml world).
I didn’t find such a function in the doc: https://ocaml.org/releases/4.10/htmlman/libref/Map.Make.html
Did I not looked at the right place?
Of course, we I can write this function by hand like:
let map_of_bindings : (string * 'a) list -> 'a StringMap.t =
List.fold_left
(fun acc (k, v) -> StringMap.add k v acc)
StringMap.empty
But 1) it is too bad I can’t use it out of the box 2) it will be specific to the StringMap module I’ve created (but I’m a OCaml noob, maybe there is a way to say “define this function on a random instance of the Map functor”?)
Regards,