Confused about how to use Belt.Map.make


The following code does not compile:

open Belt;
module IntCmp = Id.MakeComparable({
  type t = int;
  let cmp: (int, int) => int =;
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:

It seems to work fine if I try to make a Belt.Set using the same IntCmp module, so what is going on?


Ah, I figured it out. If I add some more code that uses the map then type inferencing figures out the type of the Map’s value. For example:

|. Map.set((0,0), "origin")
|. Map.toArray
|. Js.log