开发者

Syntax for nested signatures?

In my ml program I am using nested structures to structure my code. I'm defining the signatures for these structures - but I can't really get to have the signatures nested.

Example:

structure Example =
struct
  structure Code = 
  struct
    datatype mytype = Mycons of st开发者_运维知识库ring
  end
end

for this I'd like to do something like this:

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

Now this doesn't work; I get syntax errors. My questions:

  1. Is this a bad idea? If so, why?
  2. How do I do it? How do I apply the nested signature to the nested structure?


The syntax in signatures when having nested structures, requires some getting used to.

When trying to specify the signature if a structure within a signature you do it like this

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

See these Hoffman[.sml][.sig] files for a simple examples of this and have a look at the Tree[.sig] file for a bit more complex example.

Remember that you need to mention your signature specification in your structure, else it will be pointless to make the signature in the first place.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜