I would like to restructure my project from a flat file/module hierarchy into a more nested one. Here is what I have now:
. # Modules:
├── fruit_apple.ml # Fruit_apple
├── fruit_lemon.ml # Fruit_lemon
├── pie_apple.ml # Pie_apple
└── pie_lemon.ml # Pie_lemon
Here is what I want to get:
. # Modules:
├── fruit
│ ├── apple.ml # Fruit.Apple
│ └── lemon.ml # Fruit.Lemon
└── pie
├── apple.ml # Pie.Apple
└── lemon.ml # Pie.Lemon
OCaml has automatic mapping from file name to module name, but it doesn't seem to have one for directories and nested files.
I could have a pie.ml
and fruit.ml
file where I include the necessary submodules:
(* pie.ml *)
module Apple = struct
include Apple
end
module Lemon = struct
include Lemon
end
But I don't know how to resolve the ambiguity between pie/apple.ml
and fruit/apple.ml
.
I tried to study Core library, which has Core
namespace with nested modules Core.Bool
, Core.Bag
and so on, but I couldn't find a core.ml
file there which I would assume integrates all the submodules.