Generative Functors

The semantic of functor in OCaml is applicative : a functor applied to the same path always returns compatible abstract types. But if you apply to anonymous structure, it will return incompatible abstract types. This is distinct to the semantic of functors in SML where functors are always generative (X1'.t and X2'.t will be incompatible in SML).

This extension is just a kind of syntactic sugar to have generative functors in OCaml when applied to the same path.

module type S = sig type t val x : t end

module F (M : sig end) : S = struct
  type t = int
  let x = 1
end

module F_gen (M : sig end) () : S = F (M)

module E = struct end;;
module E : sig  end

module X1 = F (E);;
module X1 : sig type t = F(E).t val x : t end

module X2 = F (E);;
module X2 : sig type t = X1.t val x : t end

module X1' = F_gen (E) ();;
module X1' : S

module X2' = F_gen (E) ();;
module X2' : S

here X1.t and X2.t are compatible, but X1'.t and X2'.t are not.

You can read this Xavier Leroy’s paper (section 1 and 2) to understand the motivation behind applicative semantic.