`include` and module redefinitions

Is there a good explanation on why the following compiles ?

module B = struct
  module A = struct end
end

module C = struct
  include B
  module A = struct end
end

I would expect it to fail with:

Error: Multiple definition of the module name A.
       Names must be unique in a given structure or signature.

like the following does:

module B = struct
  module A = struct end
end

module C = struct
  module A = struct end
  include B
end

If you’re on OCaml 4.08+, I suspect it is the result of this work: https://github.com/ocaml/ocaml/pull/1892

4 Likes

Right, nice.

I’m sure there’s a very good reason why you cannot commute the two expressions but I find it a bit surprising.

Also maybe the manual should say something about it here.

In particular it’s no longer possible to understand include as simply introducing equations to the included module (at least for modules).