3 ms·
> Is the module functor compiled only once, or once for every parameter type? Only once. It does in fact miss optimization opportunities in OCaml (where ints
by colanderman 15y ago
> Is the module functor compiled only once, or once for every parameter type?
Only once. It does in fact miss optimization opportunities in OCaml (where ints and float arrays are given special treatment). In theory this can be overcome with whole-program optimization. The MLton compiler for SML (which also has functors) is such a compiler, though I do not know how it handles this particular case (I would presume it does).
I know of no other languages that allow type modularity beyond the ML family (including various derived formal logic systems). Racket (PLT Scheme) provides "units" which are a similar idea to functors but use contracts instead of types (since Racket is currently untyped). The analogue of a type in Racket is a type membership function from any value to boolean; this function can be used elsewhere in the unit. See for example: http://docs.racket-lang.org/guide/Signatures_and_Units.html http://docs.racket-lang.org/guide/Signatures_and_Units.html