rescript-vscode
rescript-vscode copied to clipboard
Module type and intellisense looks weird after functor
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
Interesting...just tested this out and it is surprising: I would expect the destructive substitution to be reflected in the tooltips and signatures. (For reference, what I would expect to see here would be what I would expect this same program translated to OCaml and using OCaml lsp to show.)
Here are some images for reference...hopefully it helps.
This is the signature for the functor, it matches what I would expect.
Here is the signature when you mouse hover over NonNegativeInt
module. It is the Make
functor signature exactly. This is not what I would expect to see.
The type hint as you are typing the function name. I would expect to see int => option<t>
here.
Type hint for the function after it has been physically typed out. It is what I expect to see.
Type hint after hitting the parentheses ...there is C.domain
again.
Here is a "fix" that gives the correct type for the NonNegativeInt
signature.
With the correct hint:
And with the correct signature:
I hit this a lot too.. Very unfortunate to have to add the typing to the saturated functor ("Module").
I have written these functors intended as a library for our other engineers and requires exactly the knowledge from them I'd like them to be able to avoid.