2011-03-08 82 views
2

在我的ml程序中,我使用嵌套结构来构造我的代码。我正在为这些结构定义签名 - 但我不能真正拥有嵌套的签名。嵌套签名的语法?

例子:

structure Example = 
struct 
    structure Code = 
    struct 
    datatype mytype = Mycons of string 
    end 
end 

为了这个,我想要做这样的事情:

signature EXAMPLE = 
sig 
    signature CODE = (* or stucture Code - doesn't matter *) 
    sig 
    datatype mytype 
    end 
end 

现在,这并不正常工作;我得到语法错误。我的问题:

  1. 这是一个坏主意吗?如果是这样,为什么?
  2. 我该怎么做?如何将嵌套签名应用于嵌套结构?

回答

3

具有嵌套结构时签名中的语法需要一些习惯。

当试图如果签名中的结构,你做这样的

signature JSON = 
sig  
    type t 

    .. some signature stuff 

    structure Converter : sig  
    type json 
    type 'a t 

    ... Converter specification stuff 
    ... using type json as the parent signatures type t  
    end where type json = t  
end 

见的这一个简单的例子,这些霍夫曼[.sml] [.sig]文件指定签名,并有一个看看树[.sig]文件的一个更复杂的例子。请记住,您需要在您的结构中提及您的签名规范,否则将签名放在第一位毫无意义。