开发者

Using module include in OCaml

开发者 https://www.devze.com 2022-12-29 13:37 出处:网络
In OCaml 3.11, I want to \"extend\" an existing module using the include directive, like so: module MyString = struct

In OCaml 3.11, I want to "extend" an existing module using the include directive, like so:

module MyString = struct
  include String
  let trim s = ...
end

No problem. But now I want to expose this module's type explicitly (i.e. in a .mli file). I want something like this:

module MySt开发者_运维百科ring : 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). How can I refer to the module type for String here (without having write it out explicitly in a sig expression)?

Thanks!


OCaml 3.12 will have a construct like module type of M that I believe would have solved your problem. Meanwhile, you can have the compiler generate the lengthy signature with ocamlc -i. Sorry, but I think it's the best you can do with 3.11.

0

精彩评论

暂无评论...
验证码 换一张
取 消