简体   繁体   English

在ocaml模块中包含所有模块

[英]Include all modules inside a module in ocaml

Imagine I have a series of modules A1..An B1..Bn all of them a complete compilation unit. 想象一下,我有一系列的模块A1..An B1..Bn个个完整的编译单元。 Now I define a two new modules with those modules as nested: 现在,我定义了两个带有嵌套模块的新模块:

(* A.mli *)
module A : sig
  module A1
  ...
  module An
end
(* A.ml *)
module A1 = A1
..
module An = An

(* B.mli *)
module B : sig
  open A
  module B1
  ...
  module Bn
end
(* B.ml *)
module B1 = B1
..
module Bn = Bn

thus the original modules are re exported using module aliases. 因此,原始模块将使用模块别名重新导出。 Note that modules in B may refer to types in modules in A1..An ! 请注意, B中的模块可能引用A1..An !中的模块类型。

now, I want to create a new module AB such that the signature is: 现在,我想创建一个新的模块AB ,使签名为:

module AB : sig
  module A1
  ...
  module An

  module B1
  ...
  module Bn
end

However I don't want to listen all individual modules, just to reexport the contents. 但是我不想监听所有单独的模块,只是想重新导出内容。 Using -open is not allowed either. 也不允许使用-open The best I can come up with is: 我能想到的最好的是:

module AB : sig
  include module type of struct include A end
  include module type of struct include B end
end

However this will fail as we lose the link between let's say, type A.A1.t and A1.t . 但是,这将失败,因为我们失去了说A.A1.tA1.t之间的联系。 Is there a way to achieve what I want? 有没有办法实现我想要的? Thanks. 谢谢。

It looks like the following would work: 看起来下面的方法可以工作:

module AB : sig
  include A
  include B
end

( module type of makes types abstracts, so you'd need to add with type ... constraints, which is messy with nested modules) (使类型抽象的module type of ,因此您需要添加with type ...约束,这对于嵌套模块来说很混乱)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM