【问题标题】:Syntax for nested signatures?嵌套签名的语法?
【发布时间】:2011-03-08 14:32:58
【问题描述】:

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

【问题讨论】:

    标签: signature ml


    【解决方案1】:

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

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

    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] 文件以获取更复杂的示例。

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

    【讨论】:

      猜你喜欢
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-14
      • 1970-01-01
      • 2015-12-14
      • 1970-01-01
      相关资源
      最近更新 更多