`module type of X ` strengthen by default
module Foo = {
type navigationApi = {
one: [#1 | rescript-lang/syntax#2],
two: int,
}
let apiImpl: navigationApi = { one: rescript-lang/syntax#1, two: 2}
}
module type Foo = module type of Foo
let foo = module(Foo: Foo)
let baz: Foo.navigationApi = switch foo {
| module(Foo) => Foo.apiImpl
}
Some internal users wrote such code snippet and got a confusing error message:
[E] Line 13, column 17:
This has type: \"Foo/1017".navigationApi
Somewhere wanted: \"Foo/1002".navigationApi
The type constructor Foo/1017.navigationApi would escape its scope
The root cause is that module type of Foo is not really Foo's type, the type equivalence is lost, so user has to write this
module type Foo = module type of Foo with type navigationApi = Foo.navigationApi
If you have many types you can list it one by one, or use
module type Foo = module type of { include Foo}
IMHO, strengthen by default is a more intuitive semantics, so that in rescript we can desugar its module type of Foo to such semantics
Should I tweak the parser to parse module type Foo = module type of Foo as module type Foo = module type of { include Foo} ?
After some thoughts, this could be done without changing the parser, move back to the compiler repo. What do you think about this proposal
Yes, the compiler would be a better place to do the transformation. It would add extra logic to the parser as we would still want to print module type of Foo and not module type of { include Foo }
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.