2012-12-18 49 views
6

我想定义一个接口PROPERTY的至少2所述的设计,和模块TypeFormula匹配它:模块和接口

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我的要求是什么?如果需要,可以添加额外的模块...

+0

驱动式注释(正交gasche的回复) :你可以很方便地用一个签名赋值来编写声明,就像'module X:SIG = ...'一样。 –

回答

6

不要将: PROPERTY密封铸件应用到模块声明中。这隐藏了返回模块的额外信息。你还是使用:

module Type = struct .. end 
module Formula = struct .. end 

如果你还需要检查TypeFormula不符合PROPERTY界面,你可以做单独:

let() = 
    ignore (module Type : PROPERTY); 
    ignore (module Formula : PROPERTY); 
    () 
+0

应用':PROPERTY'的目的是在后面我将用'PROPRETY'作为参数:'module ZFUN = functor(Prop:PROPERTY) - > struct ... end' – SoftTimur

+3

你不需要需要在'Type'和'Formula'的声明处强制抽象接口。当您应用'ZFUN'函子时,将会发生界面满意度检查。 – gasche

+0

我明白了...谢谢你... – SoftTimur