SML# Document Version 3.7.1
24 Module language declarations and interface

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. 1.

      Evaluate the structure expression and obtain a static type environment Γ.

    2. 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. 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. 4.

      Obtain a static type environment Γ by restricting the set of long names to those in Σ.

    5. 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. 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 Γ.