Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submodules should compile to the same type (objects) as file-level modules #2948

Closed
ELLIOTTCABLE opened this issue Jul 16, 2018 · 1 comment

Comments

@ELLIOTTCABLE
Copy link
Contributor

ELLIOTTCABLE commented Jul 16, 2018

Currently, if I create two ML modules in separate files,

$ cat src/test.ml
let hi _ = print_endline "Hello"

$ cat src/test_sub.ml
let sup _ = print_endline "Sup"

$ cat src/blah.js
const Test = require('./test.bs')
const Sub = require('./test_sub.bs')

Test.hi()
Sub.sup()

$ node src/blah.js
Hello
Sup

… but if I inline one of those into another, parent module …

$ cat src/test2.ml
let hi _ = print_endline "Hello"

$ cat src/blah2.js
const Test = require('./test2.bs')
const Sub = Test.Sub

console.log("Test.hi:", typeof Test.hi)
console.log("Sub.sup:", typeof Sub.sup)
console.log("Sub:", typeof Sub)
console.log("Sub (JSON):")
console.log(Sub)

$ node src/blah2.js
Test.hi: function
Sub.sup: undefined
Sub: object
Sub (JSON):
[ [Function: sup] ]

Is that … an array of functions? What!?


Coming from ML, where submodules are very often used to break down APIs, in exactly the same way as is done in JavaScript — Jest.Runner.Only over here, require('mocha').reporters.Base over there.

I can fake this by basically manually constructing my entire ‘to be exported’ API in a special file which then becomes the "main" for npm; but I really think it's preferable for BuckleScript to, with minimum effort, publicize exactly the API that one's ML interfaces already expose … no?

I hope this feedback is useful! I found this behaviour very surprising.

@bobzhang
Copy link
Member

hi @ELLIOTTCABLE Yes, this is an known prioritized issue. There are some technical challenges to change the current runtime representation of submodules, once we finish upgrading to the new compiler, we will revisit the issue.

ELLIOTTCABLE added a commit to ELLIOTTCABLE/wrange that referenced this issue Jun 12, 2019
I really can't comprehend BuckleScript's design-choices re: submodules, here. I mean, the module-system is so dang important to a ML ...

Anyway. Consider this pending <rescript-lang/rescript-compiler#2948>, I guess.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants