24.1 Structure declarations : strDecl
Syntax for structure declaration is given below.
strDecl | := | structure strbind |
strbind | ::= | strid = strexp and strbind |
strid : sigexp = strexp and strbind | ||
strid :> sigexp = strexp and strbind |
If there are multiple bindings separated with and then the structure names are bound simultaneously, whose scope is the rest of declarations that follow this declaration. So, in the following example, y is bound to 2 and not 1.
structure A = struct val a = 1 end;
structure B = struct val b = 1 end;
structure A = struct val a = 2 end and B = struct val b = A.a end;
val x = A.a;
val y = B.b;
Binding structure names with signature constraints are translated to binding to structure expressions with signature constraints as follows.
source | translated to |
---|---|
strid : sigexp = strexp | strid = strexp: sigexp |
strid :> sigexp = strexp | strid = strexp:> sigexp |
Evaluation of a structure declaration is done as follows.
-
1.
Evaluate the structure expression and obtain a static type environment and a runtime environment , as defined in the following section.
-
2.
Obtain and from and by prefixing the long names defined in them with the structure name , and add them to the current environments.
For example, if structure expression strexp generates a static type environment and a runtime value environment , then evaluating the structure declaration structure strid = strexp has the effect of extending the current type environment and runtime environment with the bindings and .