I am following the example here.
module IntPairs =struct type t = int * int let compare (x0,y0) (x1,y1) = match Stdlib.compare x0 x1 with | 0 -> Stdlib.compare y0 y1 | c -> cendmodule PairsMap = Map.Make(IntPairs)let m = PairsMap.( empty |> add (0,1) "hello" |> add (1,0) "world")
My question is, why the code doesn't compile when I add : Map.OrderedType
to the module IntPairs
definition? Like this:
module IntPairs : Map.OrderedType =struct type t = int * int let compare (x0,y0) (x1,y1) = match Stdlib.compare x0 x1 with | 0 -> Stdlib.compare y0 y1 | c -> cendmodule PairsMap = Map.Make(IntPairs)let m = PairsMap.( empty |> add (0,1) "hello" |> add (1,0) "world")
Error message:
64 | let m = PairsMap.(empty |> add (0, 1) "hello" |> add (1, 0) "world") ^^^^^^Error: This expression has type 'a * 'b but an expression was expected of type key
Isn't IntPairs
expected to implement the module type Map.OrderedType
?