The following code does not compile:
open Belt;
module IntCmp = Id.MakeComparable({
type t = int;
let cmp: (int, int) => int = Pervasives.compare;
})
let m = Map.make(~id=(module IntCmp));
The error I get is:
This expression's type contains type variables that can't be generalized:
Belt.Map.t(IntCmp.t, '_a, IntCmp.identity)
This happens when the type system senses there's a mutation/side-effect,
in combination with a polymorphic value.
Using or annotating that value usually solves it. More info:
https://realworldocaml.org/v1/en/html/imperative-programming-1.html#side-effects-and-weak-polymorphism
It seems to work fine if I try to make a Belt.Set using the same IntCmp module, so what is going on?