24.2 Structure expressions and their evaluation : strexp
Syntax for structure expressions is given below.
strexp | ::= | struct strdec end | |
longStrid | |||
strexp :sigexp | |||
strexp :>sigexp | |||
funid (strid :sigexp) | |||
funid (strdec ) | |||
strdec | ::= | decl | core language declaration |
structure strbind | |||
local strdec in strdec end | |||
strdec ; strdec |
Each of the structure expressions are evaluated as follows.
-
•
Basic structure expression : struct strdec end.
Evaluation of a basic structure expression is done by evaluating the sequence of declarations strdec. For core language declarations, bindings of variables and type constructors are generated according to the definition in Chapter 23. For structure declarations, long name bindings are generated according to the evaluation rule stated above.
-
•
Long structure identifier : longStrId.
Evaluation of this yields the type environment and the runtime environment longStrId is bound to in the current environments.
-
•
Structure expressions with signature constraints. (strexp :sigexp, strexp :>sigexp)
Evaluation of a structure expression with signature constraint is done as follows.
-
1.
Evaluate the structure expression and obtain a static type environment .
-
2.
Evaluate the signature expression according to the definition in the following subsection (24.3) and obtain a set of static constraints of long names.
-
3.
For each long name constraint in , check whether the corresponding long name binding exists in and its static value conforms to the constraint.
-
4.
Obtain a static type environment by restricting the set of long names to those in .
-
5.
If the signature constraint is an opaque constraint of the form strexp :> sigexp, then obtain from by replacing each type constructor corresponding to type spec typdesc in sigexp with an abstract type constructor.
-
6.
For constructing a runtime environment, dynamic value generation is the same as the structure expression without signature constraints, but the bound long names are restricted to those specified in .
-
1.