Core, I’m trying to make a map keyed by tuples of integers. I understand how to do something like
Map.empty (module String), but I don’t understand what’s going on fundamentally well enough to know how to make this work for something like
Map.empty (module Tuple2); I assume that I need to somehow parameterize Tuple2 with the types of its members, but I can’t figure out the syntax to do it.
I worked around it by making my own module, but that feels suboptimal
module Foo = struct module IntTuple = struct type t = int * int let compare (x0, y0) (x1, y1) = match Pervasives.compare x0 x1 with 0 -> Pervasives.compare y0 y1 | c -> c let t_of_sexp tuple = Tuple2.t_of_sexp Int.t_of_sexp Int.t_of_sexp tuple let sexp_of_t tuple = Tuple2.sexp_of_t Int.sexp_of_t Int.sexp_of_t tuple end include IntTuple include Comparable.Make(IntTuple) end
Given the above
let a = Map.empty (module Foo);; (* works as expected *) let b = Map.empty (module (int, int) Tuple2);; (* doesn't compile *),