If I want to differentiate one int type from another at compile time in order to achieve Name equivalence as opposed to Structural equivalence, then it appears that I need to define a module with an abstract type t in the signature. For example:
module type SomeId = {
type t
let make: int => t
let getValue: t => int
}
module SomeId: SomeId = {
type t = int
let make = x => x
let getValue = t => t
}
Now I can reference SomeId.t
where I previously would have indicated int
:
type something = {
id: SomeId.t,
description: string,
}
instead of:
type something = {
id: int,
description: string,
}
However, now I can not use the convenient Map.Int.t
for storing state in a map and instead need to generate a custom Map.t
using Id.MakeComparable
and something called Pervasives.compare
, for which I did not find any documentation.
Anyway, this is a long way of asking if all of this extra work is the price I have to pay to get Name equivalence? Or, is there an easier way in ReScript to accomplish this?