Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parametrized module types

Tags:

ocaml

I am trying to build a hierarchy of module types which depend on each other. In Coq I can write something like this:

Module Type Foo.
  Parameter t:Type.
End Foo.

Module Type Bar1 (T:Foo).
  Parameter f1: T.t -> T.t.
End Bar1.

Module Type Bar2 (T:Foo).
  Parameter f2: T.t -> T.t.
End Bar2.

Module Ex (F:Foo) (B1: Bar1 F) (B2:Bar2 F).

End Ex.

How would I express it in OCaml?

like image 926
krokodil Avatar asked Dec 23 '22 09:12

krokodil


1 Answers

Unfortunately, Ocaml does not directly support parameterised module types. However, you can emulate them by wrapping a parameterised module around them:

module type Foo =
sig
  type t
end

module Bar (X : Foo) =
struct
  module type T =
  sig
    val f : X.t -> X.t
  end
end

module Ex (F : Foo) (B : Bar(F).T) = ...

A bit more clumsy, but has the same effect.

like image 103
Andreas Rossberg Avatar answered Jan 07 '23 07:01

Andreas Rossberg