NEXT ·  UP ·  PREVIOUS ·  CONTENTS ·  INDEX

Signatures

One use of a signature is as a specification of a structure. That is, it may be used to describe a structure which is later to be provided. The signature states the types which will be declared in the structure and gives the type information for the values and functions in the structure.

Another use of a signature is as an interface which will hide some parts of the structure while allowing other parts to remain visible. This is achieved because it is possible for a structure to match a signature even though it declares more types and values than are required by the signature. These additional types and values are not visible.

Here is a simple signature which describes sets.

signature Set =
sig
   type ''a set
   val emptyset : ''a set
   val addset : ''a * ''a set -> ''a set
   val memberset : ''a * ''a set -> bool
end;

Now we provide an implementation of this in the form of a structure. The signature acts as a constraint on the structure in the sense that it might hide identifiers or make a polymorphic function less polymorphic and perhaps even monomorphic. It might be said that a signature constraint is used for a structure in a similar way to the way that a type constraint is used for a value.

NEXT ·  UP ·  PREVIOUS ·  CONTENTS ·  INDEX