Compiling mix-in modules in OCaml

Hi there, I’m trying to compile a language using mix-in modules (Skel) into OCaml. So basically, let’s say I have some mix-in modules described as such:

module A = struct
  type t
  val x:t
  val y:t

module A1 = clone A with type t = int
module A2 = clone A with type t = int, let x = 1
module A3 = clone A with type t = int, let x = 1, let y = 2

A way to translate mix-in modules would be to use abstract types, but then I cannot refine them, so I can’t mimic the clone directive. Another way, would be to use functors, but then it means that A2 is a functor too, which takes as argument a value for y ? This seems fine, until we have a module that clones a lot of other modules, and then it’s less obvious.

Has anybody worked on something similar ? Any input would be greatly appreciated.

Can you normalize all mixing constructs away by partial evaluation at translation time?

This is not an issue for me anymore, we chose another system.

But for the sake of the discussion, I found few works related to the subject. It seems Tom Hirschowitz and Xavier Leroy worked some time ago on designing a module system for OCaml based on mixins (1, 2), but since Xavier Leroy’s proposal for recursive modules (3) dates back to this period, I suppose they figured it was sufficient to do the part (to which I’m not sure I entirely agree, I take issue with the raise Undefined_recursive_module, but it’s not up to me :upside_down_face:).

I believe normalizing away all mixin constructs is a valid solution, but I don’t find it very satisfactory, since it doesn’t allow to keep the translation close to the source. I have not found an option I prefer though, but as I said, it’s not in my research focus anymore. Thanks for the input :slight_smile: