I’ve been developing on OCaml projects for some time now, however, it is my first time writing an OCaml library using dune.
My main issue is that I want my library to expose several modules (in particular, some modules contains functions / functors that can be used by the users, and other modules contains types (and related functions) that should be used to construct parameters for said functions / functors.
What is the best practice for doing this ?
The solution I use is simply to import these modules in the main library file, which will contain
If you want to expose all of the modules of your library, then you can simply skip writing a main library file, and dune will simply expose all the modules.
If you want to hide a few of them because they are private, then you can use the private_modules field:
(library
(name foo)
(private_modules common utils))
Writing an explicit main library file is only relevant in the following cases:
when you want to expose some modules with a different name/path, for instance module X = Foo.Bar.X
when you want to have toplevel values in your library
when you simply want to expose a different API to the outside world