Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 453
Joseph Victor Avatar asked Oct 21 '25 21:10

Joseph Victor


1 Answers

module type FOOANDBAR =
  sig 
    include FOO
    include (BAR with type b = f)
  end
like image 110
gasche Avatar answered Oct 24 '25 13:10

gasche



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!