我不熟悉OCaml,但最近一直在分析OCaml的语法。我遇到了这个包含构造,我无法看到它与哪个语法规则相关:
include Warning(Loc).S
include
的语法规则定义为
include module-expr
和moduule-expr
在括号后面不允许有点。我怀疑它是一个扩展。有人可以指出这包括平均值和与之相关的规则吗?
答案 0 :(得分:1)
语法是指包含
中的签名S
module SpecificWarning = Warning (Loc)
include SpecificWarning.S
在这种情况下,语法允许匿名构建SpecificWarning
include (Warning(Loc)).S
语法规则链接在the rule for module-type
下,看到它允许有效modtype-path
segments允许extended-module-name
s(例如,模块名称可能通过括号仿函数应用程序语法扩充),后跟{ {1}}然后从通过仿函数应用程序创建的匿名模块中充当.
的标识符。
答案 1 :(得分:0)
您指的是模块,但确实不允许这些模块。但是这个例子是关于签名,也就是模块类型。这是激励演示:
OCaml version 4.01.0
# module type S = sig type t end;;
module type S = sig type t end
# module Make(T : S) = struct
module type S = sig
type t = T.t list
end
end;;
module Make :
functor (T : S) -> sig module type S = sig type t = T.t list end end
# module type Example = sig
include Make(String).S
end;;
module type Example = sig type t = String.t list end
#