我想定义一个接口PROPERTY,至少有2个模块Type并Formula匹配它:
module type PROPERTY =
sig
type t
val top : t
val bot : t
val to_string: t -> string
val union: t -> t -> t
val intersection: t -> t -> t
end
module Type = (struct
type t =
| Tbot
| Tint
| Tbool
| Ttop
...
end: PROPERTY)
module Formula = (struct
type t =
| Fbot
| Ftop
| Fplus of int * Type.t
...
let union =
... Type.union ...
...
end: PROPERTY)
Run Code Online (Sandbox Code Playgroud)
有两个要求:
1)我想在Type外面调用构造函数(如有必要,所有程序)
2)Formula包含值的某些值的一部分Types,例如Fplus (5, Type.Tint)类型Formula; 还有一些函数Formula需要调用一些函数Type,例如Formula.union需要调用Type.union
谁能告诉我如何修改上面的声明来满足我的要求?如有必要,可以添加额外的模块......
不要将: PROPERTY密封模具应用于模块声明.这会隐藏返回模块的额外信息.你应该使用:
module Type = struct .. end
module Formula = struct .. end
Run Code Online (Sandbox Code Playgroud)
如果您仍想检查Type并Formula确实满足PROPERTY界面,可以单独执行此操作:
let () =
ignore (module Type : PROPERTY);
ignore (module Formula : PROPERTY);
()
Run Code Online (Sandbox Code Playgroud)