I\'m trying to understand a specific thing about ocaml modules and their compilation:
am I forced to redeclare types already declared in a .mli
inside t
In general, yes, you are required to duplicate the types.
You can work around this, however, with Camlp4 and the pa_macro
syntax extension (findlib package: camlp4.macro
). It defines, among other things, and INCLUDE construct. You can use it to factor the common type definitions out into a separate file and include that file in both the .ml
and .mli
files. I haven't seen this done in a deployed OCaml project, however, so I don't know that it would qualify as recommended practice, but it is possible.
The literate programming solution, however, is cleaner IMO.