Unbound module when defining a Map type

Hi,

I need to define a Map type (keys of type Id, values of type t). It was working fine in ReasonML, however I’m unable to define the Map type in Rescript. Am I getting the syntax wrong?

module Id = {
  type t =
    | Id(int)
  ...
}

type t = {...}

module IdMap = {
  type t = Id.t
  include Comparator.Make({
    type nonrec t = t
    let compare = Id.compare
  })
}

// getting error: Unbound module type IdMap
type myMap = Map.t<module(IdMap), t, IdMap.identity>

Why is the module type IdMap unbound? The module is defined right above. Am I getting the syntax wrong?

Thanks!

I’m not sure your code is doing what you intend it to do. I assume Map is an alias for Belt.Map, in which case your myMap type is actually defining a map whose keys are type module(IdMap), which means the entire module would be used as a key (passed as a first-class module). I assume you mean to use Id.t as the key type.

However, to directly answer the question, module IdMap = ... is a module implementation, not a module type. You can either define the module type by hand or use module type of as a shortcut, e.g.: module type IdMap = module type of IdMap.

2 Likes