3

在我的 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. 我该怎么做?如何将嵌套签名应用于嵌套结构?
4

1 回答 1

4

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

尝试指定签名时,如果签名中的结构您这样做

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

请参阅这些 Hoffman[ .sml ][ .sig ] 文件以获得一个简单的示例,并查看 Tree[ .sig ] 文件以获得更复杂的示例。

请记住,您需要在结构中提及您的签名规范,否则首先制作签名将毫无意义。

于 2011-03-10T05:15:25.300 回答