1) open is similar to import , it adds the exported definitions to the open module in the local namespace. include adds them to the module, as if you copied the definitions from the included module into the includeee. ìnclude will also export definitions (if there is no file / interface signature that limits what is exported, of course)
2), you should prefer the most local use of the module, which is convenient so as not to pollute the namespace unnecessarily. Thus, you usually want to use direct access, and only if the module was specifically designed to open at the file level, if you do. However, there are open forms that are more local than the file level. You can open module only in the scope of a function or even tied to a single expression in the form Foo.(someFunction 4 |> otherFunction 2)
3) Toplevel modules (file) must be implemented as a rei file with the same name as the re file. However, you can define module types as “interfaces” for submodules.
The modular system of OCaml is quite extensive and flexible. I recommend reading the chapter in the Real World Ocaml module to better understand it: https://realworldocaml.org/v1/en/html/files-modules-and-programs.html
source share