【问题标题】:Include all modules inside a module in ocaml在 ocaml 中包含一个模块内的所有模块
【发布时间】:2017-07-20 18:33:10
【问题描述】:

假设我有一系列模块A1..AnB1..Bn,它们都是一个完整的编译单元。现在我定义了两个新模块,这些模块是嵌套的:

(* 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

因此原始模块使用模块别名重新导出。请注意,B 中的模块可能会引用 A1..An 中的模块中的类型!

现在,我想创建一个新模块AB,签名为:

module AB : sig
  module A1
  ...
  module An

  module B1
  ...
  module Bn
end

但是我不想听所有单独的模块,只是为了重新导出内容。也不允许使用-open。我能想到的最好的是:

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

但是,这将失败,因为我们失去了假设,输入 A.A1.tA1.t 之间的链接。有没有办法实现我想要的?谢谢。

【问题讨论】:

    标签: module ocaml


    【解决方案1】:

    看起来以下方法可行:

    module AB : sig
      include A
      include B
    end
    

    module type of 使类型抽象,因此您需要添加 with type ... 约束,这对嵌套模块很乱)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-01
      • 1970-01-01
      • 2020-01-26
      相关资源
      最近更新 更多