I would like to know if it is possible to reduce a list of first class modules into one modules. The goal would be to generate the cartesian product of an arbitrary number of algebraic structures.
For instance, given a signature SGroup
:
module type SGroup = sig
type t
val add : t -> t -> t
end
and a functor
module Product (G1:SGroup)(G2:SGroup) : SGroup = struct
type t = G1.t * G2.t
let add (x1,x2) (y1,y2) = (G1.add x1 y1,G2.add x2 y2)
end
I can define a list of first class modules:
let sgroups_list =
[
(module struct
type t = int
let add = ( + )
end : Group);
(module struct
type t = float
let add = (+.)
end : Group)
]
Is there a way to “fold” such (non-empty) list of first class modules using Product
?