haikkkk
haikkkk

Reputation: 21

How to change Map.key to String in OCaml?

First I've defined

module StringMap = Map.Make(String);;

and I have a list generated by StringMap.bindings, the types in the list are (StringMap.key × int).I want to use the key as a string so that I can compare them, how could I change its the type of the list?

Upvotes: 1

Views: 682

Answers (1)

Jeffrey Scofield
Jeffrey Scofield

Reputation: 66818

Your type StringMap.key is a synonym for string. There is no need to convert, they are the same type.

# let mymap = StringMap.singleton "abc" 14;;
val mymap : int StringMap.t = <abstr>
# StringMap.bindings mymap;;
- : (StringMap.key * int) list = [("abc", 14)]
# fst (List.hd (StringMap.bindings mymap)) = "abc";;
- : bool = true

Upvotes: 3

Related Questions