10
我有以下情况:函子与多个参数OCaml中
module type M = sig type s = ... end
module Make(P: Something) : (M with type s = P.t) = struct
type s = P.t
...
end
工作正常生成用具体的实施及其实施内部Something
类型的模块,M
类型的模块。
现在假设我有另外一个模块定义为
module type AU = sig
val feed : float -> unitv
val nth : int -> (float -> float)
val reset : unit -> unit
end
有各种实现
module SUAlg : AU = struct ... end
module MLAlg : AU = struct ... end
module ACEAlg : AU = struct ... end
这个问题的一点是,M
模块应该结束了两件事情被参数:一个Something
模块和AU
模块,以便它类似于
module Make(P: Something) : (M with type s = P.t) = struct
type s = P.t
module Alg = MLAlg (* just an example *)
...
end
但我想有一个通用仿函数给出Something
并给出AU
它会生成一个模块,它具有两个具体实现。有没有办法轻松获取?
由于函子的语法很奇怪,我仍然对它不熟悉,我不知道我问的是否可以用简单的方法解决。
在此先感谢
是否有将参数传递给函子的不同语法? Make_LOffset(arg1 arg2)? – stumped 2016-10-06 16:38:17
@stumped那么参数将会是模块,所以它们看起来像'Arg1'和'Arg2'。语法是'Make_LOffset(Arg1)(Arg2)'。我已经更新了答案。 – 2016-10-06 19:56:28