Module 在OCaml中使用模块include
在OCaml 3.11中,我想使用include指令“扩展”现有模块,如下所示:Module 在OCaml中使用模块include,module,types,expression,ocaml,Module,Types,Expression,Ocaml,在OCaml 3.11中,我想使用include指令“扩展”现有模块,如下所示: module MyString = struct include String let trim s = ... end 没问题。但是现在我想显式地公开这个模块的类型(即在.mli文件中)。我想要这样的东西: module MyString : sig include String val trim : string -> string end 但include语法不正确,因为字符串引用的
module MyString = struct
include String
let trim s = ...
end
没问题。但是现在我想显式地公开这个模块的类型(即在.mli文件中)。我想要这样的东西:
module MyString : sig
include String
val trim : string -> string
end
但include语法不正确,因为字符串引用的是一个模块,而不是模块类型(编译器确实是barf)。我如何在这里引用String的模块类型(而不用在sig表达式中显式写出它)
谢谢 ocaml3.12将有一个类似于
模块类型M
的结构,我相信它会解决您的问题。同时,您可以让编译器使用ocamlc-i
生成冗长的签名。对不起,但我认为这是你用3.11能做的最好的了