Download Specware 4.2 Language Manual

Transcript
Chapter 2. Metaslang
Restriction. The type information, if any, presented in an op-definition must be
consistent with the type specified by the preceding op-declaration. For example, the
presence of a type-variable-binder signals that the op being defined is polymorphic,
but then the op-declaration must contain an identical type-variable-binder. (A
type-variable-binder may be needed to introduce local-type-variables for employ in
type-annotations within the defining expression, as exemplified in the first definition
for o.)
In Specware 4.2, an op still may be defined without having been previously declared,
but this is now a deprecated feature. When an op is defined without having been
declared, the op-definition generates an implicit op-declaration for the op, provided a
monomorphic type for the op can be unambiguously determined from the op-definition
together with the uses of the op in applications and other contexts, so that all
expressions can be assigned a type in the context in which they occur. This feature
may not persist in future releases, so users are advised to provide an op-declaration
somewhere before each op-definition, either in the same spec or (more typically) in an
imported spec. Alternatively, the newly expanded syntax for op-definitions makes it
simple to both give a unique type to and define an op within one declaration.
In a model of the spec, an indexed family of typed values is assigned to a polymorphic
op, with one family member for each possible assignment of types to the
local-type-variables of the type-variable-binder, and the type of that value is the
result of the corresponding type-instantiation for the polymorphic type of the op.
Thus, we can reduce the meaning of a polymorphic op-definition to a family of
(fictitious) monomorphic op-definitions.
An op-definition with formal-application
def op H P = E
in which H is a formal-application-head, P is a formal-parameter and E an
expression, is equivalent to the op-definition
def op H = fn P -> E
For example,
def o (f, g) x = f(g x)
is equivalent to
def o (f, g) = fn x -> f(g x)
which in turn is equivalent to
40