Reputation: 2608
I created a new module which is just a shorter alias for a module with a very long name:
module M = ModuleWithLongName
I'm in a situation where the size of the final executable matters. Is the above construct handled sanely by the compiler (i.e. M
is really just an alias), or does it replicate the entire contents of ModuleWithLongName
inside the module where M
is defined?
Upvotes: 4
Views: 715
Reputation: 6738
An alias for a module_path, I think.
Module moduleName = module_expr
And module_expr ::= module_path | ...
See module_expr production syntax
Upvotes: 0
Reputation: 31459
No, the OCaml language does not support "true module aliasing".
However, you probably won't notice until you try fairly advanced combination of functors and abstract types. In particular, you can only observe this issue in the type system, not in the runtime behavior of programs: modules are sometimes copied, but mutable states would be aliased between copies (in your example, if ModuleWithLongName.foo
is a mutable reference, then M.foo
is the same reference).
If you use first-class modules, or define local modules in deeply nested functions, you might observe module copy operations as a non-neglectible cost in the overall computation. The right mental model to reason about performance of first-class modules is that, after type-checking and module-checking, they're exactly records.
Upvotes: 8