I’ve seen a few OCaml libraries that use (eg dune-engine) or expect that one uses (eg accessor) an
import.ml file, seemingly to collect together multiple
opens and fix-up definitions. I’ve never used
import.ml, mainly because these days I tend to like keeping things explicit, but I’m now wondering:
- What are the advantages of structuring common imports this way? Are there any disadvantages?
- Is this a standard project convention? If other people worked on my OCaml projects, would they be confused by the fact that all my imports are scattered in the files that import them?
- Say I have a project named
foowhere the libraries are all named
Foo_baz, etc, but are in directories
/bazetc. Should I be using an
import.mltype thing with
module Bar = Foo_bar;; module Baz = Foo_baz;;and so on to hide the discrepancy, or is this obfuscating?
- When is it a good idea to
openlibraries into the
import.mlwholesale, and when should I just make shorthand aliases? (Certainly
Basewould be opened, and maybe some of the
Accessordefinitions, but otherwise… hmm.)
- Should these sorts of files always be
open Import'd, or should I be setting the compiler to open them implicitly (and how would one do that in Dune)?