我想定义一个接口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)
有两个要求:
1)我想的Type
构造函数可以外部调用(所有节目如有必要)
2)的Formula
一些值的一部分包含的Types
值例如Fplus (5, Type.Tint)
的类型为Formula
;也Formula
一些功能需要调用的Type
一些功能,例如,Formula.union
需要调用Type.union
谁能告诉我如何修改上述声明fullfil我的要求是什么?如果需要,可以添加额外的模块...
驱动式注释(正交gasche的回复) :你可以很方便地用一个签名赋值来编写声明,就像'module X:SIG = ...'一样。 –