https://facebook.github.io/reason/modules.html#modules-basic-modules
I don’t see any import or require in my file; how does module resolution work?
Reason/OCaml doesn’t require you to write any import; modules being referred to in the file are automatically searched in the project. Specifically, a module Hello asks the compiler to look for the file hello.re or hello.ml (and their corresponding interface file, hello.rei or hello.mli, if available).
A module name is the file name, capitalized. It has to be unique per project; this abstracts away the file system and allows you to move files around without changing code.
我尝试了 Reason 模块系统,但无法理解其工作原理。
1) open
和 include
有什么区别?
2) 我有一个定义了模块 Foo
的文件 foo.re
,我有另一个文件 bar.re
,想要调用 Foo
模块中的函数。
在 bar.re
中,我应该 open
还是 include
Foo
模块?还是直接访问 - Foo.someFunction
?
3) 模块接口只能在 *.rei
文件中实现吗?并且模块接口文件应该与同名但扩展名为 rei
的文件相同吗?