Hi, I’m an Ocaml beginner and I would appreciate feedback about this idea related to information hiding ![]()
Ocaml .mli files offer a great way to declare some definitions as private. However, in a bit larger programs we may want to additionally declare visibility at a higher level, so that a module is explicitly available to a subset of our program. I found that there are multiple ways to achieve this:
-
Approach 1: The ocaml website presents Library Wrapper Modules, which works fine. However, in a way this adds (with my intuition…) unnecessary indirection, making the program more complex.
-
Approach 2 (is there a term for this?): Structuring the project into relatively large .ml “library” files, each containing large number of modules. The mli files would thus expose only some modules from this “library”, similar to the library wrapper module explained above. We can declare inline module signatures to achieve information hiding at the individual module level too.
I think the main advantage of approach 2 over approach 1 is that it’s simpler, but it still achieves same degree of abstraction. One nuisance of approach 2 is that the files would be quite large. But is that inherently negative? Text editors usually have code folding, etc. And I feel that the Ocaml language features support well this style of programming.