Search code examples
moduleocamlsubtype

Subtyping and Module Inclusion in OCaml


Suppose I have the following setup

module type FOO = sig type f val do_foo : f end
module type BAR = sig type b val do_bar : b end


module type FOOANDBAR =
  sig 
    include FOO
    include BAR
  end

Now I want to (in a nice way, aka, without copying the interface and so that FOO and BAR are still subtypes) enforce the restriction that the type f and the type b are the same.

Is there a nice way to do this in OCaml, possibly using some different approach that the include keyword?

thanks!! -Joseph


Solution

  • module type FOOANDBAR =
      sig 
        include FOO
        include (BAR with type b = f)
      end