[英]Using module include in OCaml
In OCaml 3.11, I want to "extend" an existing module using the include directive, like so: 在OCaml 3.11中,我想使用include指令“扩展”现有模块,如下所示:
module MyString = struct
include String
let trim s = ...
end
No problem. 没问题。 But now I want to expose this module's type explicitly (ie in a .mli file).
但现在我想明确地公开这个模块的类型(即在.mli文件中)。 I want something like this:
我想要这样的东西:
module MyString : sig
include String
val trim : string -> string
end
But the include syntax is not correct because String refers to a module, not a module type (and the compiler does indeed barf). 但是include语法不正确,因为String指的是模块,而不是模块类型(编译器确实是barf)。 How can I refer to the module type for String here (without having write it out explicitly in a sig expression)?
我如何在这里引用String的模块类型(没有在sig表达式中明确地写出来)?
Thanks! 谢谢!
OCaml 3.12 will have a construct like module type of M
that I believe would have solved your problem. OCaml 3.12将有一个类似
module type of M
构造,我相信它会解决你的问题。 Meanwhile, you can have the compiler generate the lengthy signature with ocamlc -i
. 同时,您可以让编译器使用
ocamlc -i
生成冗长的签名。 Sorry, but I think it's the best you can do with 3.11. 对不起,但我认为这是你用3.11做的最好的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.