|
Note that the declaration of a structure, signature or functor
is not a declaration (dec).
It can only occur at the top-level of a program.
A structure, signature or functor is used in a specification (spec)
not in an expression or a normal declaration (dec)
(except to open a structure).
Although
structure:signature is "like"
value:type and
a functor is "like" a function,
it is only a matter of "like".
Structures, signatures and functors belong very much to compile-time.
E.g. Traversable
Here is a simple example of Traversable data structures --
where the elements can be extracted in some systematic order.
For this example, a structured data type is Traversable if
it has functions (~methods)
initialise, next, advance and toList,
an elementType, and a state for a traverse.
For example,
't list and 't tree
can be made Traversable.
[an error occurred while processing this directive]
|
|
SML:
:: | cons |
[x1,...] | list |
[ ] | list |
@ | append |
fn => | &lambda . |
: | has type |
Compared
|
structure, struct; signature, sig; functor
|
|
|