Closed kevinsimper closed 1 month ago
@kevinsimper open X;
makes all of the things in X
available without the module specifier in your current module; something like this:
open School;
let anotherPerson: profession = Teacher;
print_endline(getProfession(anotherPerson));
If you don't want to do that, you can always just write
let anotherPerson: School.profession = School.Teacher;
print_endline(School.getProfession(anotherPerson));
without the open
:)
@kevinsimper open
is discouraged from the docs of your snippet precisely because of these reasons. However, we can provide a better help here. Do you have an example snippet where this warning triggers?
@ubsan @chenglou thank you for your responses, I did try to remove Open
, but then I get this error in the default bs-platform
tool:
let anotherPerson: School.profession = School.Teacher;
print_endline(School.getProfession(anotherPerson));
$ npm start
> my-first-app@0.1.0 start /Users/kevinsimper/Projects/test/my-first-app
> bsb -make-world -w
Package not found: resolving package School in /
File "bsconfig.json", line 1
Error: package School not found or built , if it is not built
Please run 'bsb -make-world', otherwise please install it
>>>> Start compiling
Rebuilding since just get started
Package not found: resolving package School in /
File "bsconfig.json", line 1
Error: package School not found or built , if it is not built
Please run 'bsb -make-world', otherwise please install it
>>>> Finish compiling(exit: 2)
Your configuration is wrong. What's your bsconfig.json like? There shouldn't be any mention of school
in it
@chenglou sorry, that was a attempt to make it work, here is without, I would love to know what I do wrong, then I can help with the docs for newcomers that has the same troubles as I have
https://github.com/kevinsimper/my-first-reasonml
$ npm start
> my-first-app@0.1.0 start /Users/kevinsimper/Projects/test/my-first-app
> bsb -make-world -w
>>>> Start compiling
Rebuilding since just get started
ninja: Entering directory `lib/bs'
[1/1] Building src/demo-MyFirstApp.cmj
FAILED: src/demo-MyFirstApp.cmj /Users/kevinsimper/Projects/test/my-first-app/src/demo.bs.js src/demo-MyFirstApp.cmi
/Users/kevinsimper/.nvm/versions/node/v9.1.0/lib/node_modules/bs-platform/lib/bsc.exe -bs-package-map my-first-app -bs-package-output commonjs:src -bs-assume-no-mli -bs-no-builtin-ppx-ml -bs-no-implicit-include -I . -I src -w -30-40+6+7+27+32..39+44+45+101 -bs-suffix -nostdlib -I '/Users/kevinsimper/Projects/test/my-first-app/node_modules/bs-platform/lib/ocaml' -no-alias-deps -color always -bs-re-out -bs-super-errors -o src/demo-MyFirstApp.cmj -c src/demo.mlast
We've found a bug for you!
/Users/kevinsimper/Projects/test/my-first-app/src/demo.re 1:20-36
1 │ let anotherPerson: School.profession = School.Teacher;
2 │ print_endline(School.getProfession(anotherPerson));
This type constructor's parameter, `School.profession`, can't be found. Is it a typo?
ninja: build stopped: subcommand failed.
>>>> Finish compiling(exit: 1)
I got help from @cem2ran, it was because a file itself declares a module, so you don't need to declare it inside the file as well. I did not understand that from this page, https://reasonml.github.io/guide/language/module
To improve this, would it make sense to make another page about file structure and modules? And adding something here about the equivalent of node.js module.exports
and exports
?
Doesn’t seem like a bug
What should I do here? Creating this issue because there is no good resources anywhere about this if you are a beginner to reasonml.
I do a lot of Node.js and the biggest for thing for me to get with reasonml is how to split up your app between files like you would do with require(). I have looked at the generated output and understand that.
Found this link https://stackoverflow.com/a/26824143/804984
You can remove the warning by doing
open! ..
but the docs does not say anything about it.School.re
demo.re