Is the OCaml compiler compatible with a true modular alias?

I created a new module, which is just a shorter alias for a module with a very long name:

module M = ModuleWithLongName 

I am in a situation where the size of the final executable file matters. Is the construct described above processed by the compiler (i.e., M really just an alias) or is it replicating the entire contents of ModuleWithLongName inside the module, where M defined?

+4
source share
3 answers

No, OCaml does not support true module anti-aliasing.

However, you probably won't notice until you try a fairly complex combination of functors and abstract types. In particular, this problem can only be observed in the type system, and not during program ModuleWithLongName.foo : modules are sometimes copied, but mutable states will be smoothed between copies (in your example, if ModuleWithLongName.foo is a mutable link, then M.foo is one same link).

If you use first-class modules or define local modules in deeply nested functions, you can observe the operation of copying modules as an invaluable cost in general computing. The right mental model for determining the performance of first-class modules is that after type checking and module checking, they are accurately written.

+8
source

Starting with version 4.02, OCaml supports true alias module .

+2
source

Alias ​​for module_path, I think.

Module moduleName = module_expr

And module_expr :: = module_path | ...

See production syntax module_expr

0
source

All Articles