Chapter 10Language extensions

15Generative functors

(Introduced in OCaml 4.02)

module-expr::= ...  
 functor()->module-expr
 module-expr()
 
definition::= ...  
 modulemodule-name  { (module-name:  module-type) ∣  () } [ :module-type ]  =  module-expr
 
module-type::= ...  
 functor()->module-type
 
specification::= ...  
 modulemodule-name  { (module-name:  module-type) ∣  () } :module-type
 

A generative functor takes a unit () argument. In order to use it, one must necessarily apply it to this unit argument, ensuring that all type components in the result of the functor behave in a generative way, i.e. they are different from types obtained by other applications of the same functor. This is equivalent to taking an argument of signature sig end, and always applying to struct end, but not to some defined module (in the latter case, applying twice to the same module would return identical types).

As a side-effect of this generativity, one is allowed to unpack first-class modules in the body of generative functors.