views:

44

answers:

1

Hello, I've the following situation:

module type M = sig type s = ...  end

module Make(P: Something) : (M with type s = P.t) = struct
   type s = P.t
   ...
end

that works fine to generate modules of M type that use specific implementation of modules of type Something inside their implementation.

Now suppose I have another module defined as

module type AU = sig
  val feed : float -> unitv
  val nth : int -> (float -> float)
  val reset : unit -> unit
end

that has various implementations

module SUAlg : AU = struct ... end
module MLAlg : AU = struct ... end
module ACEAlg : AU = struct ... end

The point of the question is that the M module should be parametrized over two things now: a Something module and a AU module so that it's something like

module Make(P: Something) : (M with type s = P.t) = struct
   type s = P.t
   module Alg = MLAlg (* just an example *)
   ...
end

but I would like to have a generic functor that given a Something and given an AU it produces a module with both things concretized. Is there a way to obtain that easily?

Since functor syntax is quite strange and I'm still new to it I don't know if what I'm asking can be solved in a simple way or not.

Thanks in advance

+6  A: 

Yes, a functor can have several arguments. The syntax is like this:

module Make_LOffset
            (V:Lattice_With_Isotropy.S)
            (LOffset : Offsetmap.S with type y = V.t and type widen_hint = V.widen_hint) =
struct
   …
end

In this example, that I took from existing code so I would be sure that it is syntactically correct, Make_LOffset is parameterized by two modules V and LOffset, of respective signatures Lattice_With_Isotropy.S and Offsetmap.S, and there are additional type constraints between the two signatures.

Pascal Cuoq