Extending a module

Hello all,

Is it possible to extend module A so that it contains new functions using type s below?

(* a.ml *)

module A = struct
  type t = ...
end
type s = A.t * A.t
(* Would like to add a function 'make_s' that uses type s to module A *)
module A = struct (* << This doesn't work because it causes 'Multiple definition of the module name A' error. *)
  include A
  let make_s (x: t): s = (x, x)
end

If creating a .mli file could be avoided it will be the best solution, but if it is unavoidable I am happy with the solution.

Thanks again,

It is not possible to define the same module name multiple times in the same scope. You can either rename the first instance of A to something else, or move it to a different scope (a different file, a submodule, etc).

Cheers,
Nicolas

1 Like

The best option is probably to have a private “base” module, and expose derived modules that extend the base in some way.