|
|
| ||||||
| 9.3 Declarations | ||||||||
A declaration translates to one or more type, constant, function or variable declarations as described below for the various kinds of declarations.
Apart from the top level module (which is translated as if it were an object), schemes are only translated when they are instantiated as objects. So a scheme that is instantiated several times will therefore be translated several times. This may appear wasteful, but it saves the need for the restrictions on scheme parameters that would be needed if functors were used for schemes.
An object translates as its translated declarations in a structure of the same name as the object.
An object definition in RSLSML cannot have a formal array parameter.
Type declarations are translated according to their constituent definitions.
Mutually recursive type definitions are not accepted.
Not accepted.
A variant definition translates to a structure containing an SML datatype defining the constructors, plus definitions of any destructors and reconstructors. Equality and "toString" functions are also defined.
Wildcard constructors are not accepted.
A short record definition translates to a structure containing an SML datatype defining the constructor, plus definitions of any destructors and reconstructors. Equality and "toString" functions are also defined.
An abbreviation definition translates to an SML type definition.
Typings are not accepted.
An explicit value definition translates to an SML value definition.
Implicit value definitions are not accepted.
An explicit function definition translates to an SML function definition.
If the parameter type(s) are subtype(s), run-time checking that arguments satisfy the relevant conditions is included.
If there is a precondition, run-time checking the the precondition is true when the function is invoked is included.
Access descriptors are ignored. The kind of function arrow (→ or -~->) does not matter.
It is not required that the number of parameters matches the number of components in the domain of the function's type expression. For example, the following are all accepted:
| type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| U = Int × Bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f1: Int × Bool → Bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f1(x, y) ≡ ..., | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f2: (Int × Bool) → Bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f2(x, y) ≡ ..., | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f3: U → Bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f3(x, y) ≡ ..., | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f4: U × Int → Bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f4(x, y) ≡ ..., | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f5: (Int × Bool) × Int → Bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f5(x, y) ≡ ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f6: (Int × Bool) × Int → Bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f6(x) ≡ ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f7: Int × Bool → Bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f7(x) ≡ ..., | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f8: (Int × Bool) → Bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f8(x) ≡ ..., | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f9: U → Bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f9(x) ≡ ..., | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f10: U × Int → Bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f10((x, y), z) ≡ ..., | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f11: (Int × Bool) × Bool → Bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f11((x, y), z) ≡ ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Implicit function definitions are not accepted.
A variable declaration translates to SML variable definitions.
If the variable type is a subtype, run-time checking that the initial value is in the subtype is included.
Multiple variable definitions, and uninitialised single variable definitions are not accepted.
Not accepted.
Not accepted.
| 9.3 Declarations | ||||||||
|
|
| ||||||