Hi all, I have a module function of multiple arguments (simplified here), where the second argument depends on the first.:
module Example = (A : {type t}, B : {let x : A.t}) => { ... }
In reality, the module types for the arguments A and B are much larger, so I want to define some module types for them, but I can’t see how to declare the type of B separately where the module A is in scope.
module type AType = {type t}
module type BType = ???
The module type for B will need an abstract type in order to have something to substitute, but the substitution can be destructive so that the module doesn’t have to define it:
module type B = {
type t
let value: t
}
module M: B with type t := int = {
let value = 42
}
Note that := is used for the type substitution, instead of =, to specify that the substitution is destructive.
Indeed I was missing glennsl technique, with this you can have:
module type AType = {
type t
}
module type BType = {
type t
let x: t
}
module Example = (A: AType, B: BType with type t := A.t) => {
let x = B.x
}
module MyExample = Example({type t = int}, {let x = 2})
That looks pretty close to what you were trying to achieve I think @liamoc.