3

I'm very new to Reason. I have a tuple containing two strings and want to make a Map where the keys are of that tuple type.

How should I go about doing it?

Yangshun Tay
  • 49,270
  • 33
  • 114
  • 141
  • 1
    Possible duplicate of [How do I declare a map type in Reason ML?](https://stackoverflow.com/questions/48830710/how-do-i-declare-a-map-type-in-reason-ml) – glennsl Jul 10 '19 at 21:46
  • 1
    The documentation page also shows an example of creating a map of tuples (OCaml syntax though :-) https://reasonml.github.io/api/Map.html – Yawar Jul 11 '19 at 19:40

1 Answers1

4

Map.Make is a functor, which means it expects a module as its argument, not a type. The module argument must conform to the OrderedType signature:

module type OrderedType = {
  type t
  let compare : (t, t) => int
}

In your case that would be something like:

module TuplesMap = Map.Make({
  type t = (string, string)
  let compare = (a, b) => ...
});

Then all you need to do is to implement the compare function.

glennsl
  • 28,186
  • 12
  • 57
  • 75