How to handle namespacing

This section of the docs says that using namespacing is almost mandatory. However, if I enable namespacing for my project foo, how do I define/expose something in the “root” of this namespace without introducing a “submodule” between it?

Example: I want the consumers of my library to use Foo.myFunc, but if I place this function in a file, this will introduce a module with the same name as the file, so it becomes Foo.File.myFunc.

I see lots of libraries not using namespacing, but instead having a Foo.res file that (re)exports everything, and lots of Foo__Submodule.res files next to that. Is this idiomatic?


ReScript’s namespace feature doesn’t allow putting any items in the top-level namespace, other than the modules it puts there automatically. That’s why some projects opt to manually manage the namespacing. It offers more control. Here’s an example of this that I consider good practice: