rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

`module type of X ` strengthen by default

Open bobzhang opened this issue 4 years ago • 3 comments

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

bobzhang avatar Jun 10 '21 02:06 bobzhang

Should I tweak the parser to parse module type Foo = module type of Foo as module type Foo = module type of { include Foo} ?

IwanKaramazow avatar Jun 13 '21 07:06 IwanKaramazow

After some thoughts, this could be done without changing the parser, move back to the compiler repo. What do you think about this proposal

bobzhang avatar Jun 13 '21 07:06 bobzhang

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 }

IwanKaramazow avatar Jun 14 '21 15:06 IwanKaramazow

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.

stale[bot] avatar Jun 10 '23 00:06 stale[bot]