I’m using functors to generate validated primitive types, like a NonNegativeInt
. It works. But the tooltip/intellisense for using the functor is kind of strange. For example, in the code below when I try to use my NonNegativeInt
method here is what I see…
What I want to see is int
instead of C.domain
. At this point, what is module C? If I want all traces of C.domain
to be replaced with int
I think I need to do the BetterNonNegativeInt
casting/assignment below, which is an extra step. Is there some way to do all this in a single step? Is this a problem with the VS Code extension?
module type T = {
type t
type domain
let eq: (t, t) => bool
let make: domain => option<t>
let value: t => domain
}
module type Configuration = {
type domain
let cmp: (domain, domain) => float
let validate: domain => option<domain>
}
module Make = (C: Configuration): (T with type domain := C.domain) => {
type t = C.domain
type domain = C.domain
let eq = (i: t, j: t) => C.cmp(i, j) === 0.0
let value = i => i
let make = (i: domain) => C.validate(i)
}
module NonNegativeInt = Make({
type domain = int
let cmp = (x, y) => x < y ? -1.0 : x > y ? 1.0 : 0.0
let validate = i => i >= 0 ? Some(i) : None
})
module BetterNonNegativeInt: T with type domain := int = NonNegativeInt