How can I have a module signature where one of the values accepts a first-class module of that very same signature? MWE:
module type SIG = sig
type t
val size : int
val convert : (module SIG) -> t -> P.t option
end
module Make (Params : sig val size : int end) : SIG = struct
type t = int
include Params
let convert (module P : SIG) x = Some x
end
Let’s say Make(struct let size = foo end)
is supposed to represent positive integers smaller than size
, and I want a convert
function to convert P.t
and Q.t
where P
and Q
are different instances of this same functor (with possibly different sizes). Is this possible to express in OCaml?