Support is provided for defining module types . These are
essentially record types
, where the type of each field of an instance
can depend on previous fields of the instance. They are very useful
for defining ADT's
(abstract data types
) and algebraic classes.
Module types are allowed to have parameters. For example, an ADT for
queues could be created that takes the type of queue elements as a
parameter. Module types are currently implemented using Nuprl
's
type.
An ML function create_module helps with setting up new module type definitions, adding projection functions, and updating the
AbReduce tactic to recognize applications of the projection functions.
The create_module function should be used as follows:
The abstractions for modules currently reside in the ml_1 theory.
The abstraction holding the create_module invocation has the editor alias classdecl. Enter it in the ML object by opening up a term slot in the object's top level text sequence, and typing the name classdecl. By keeping the top level of the ML object a text sequence, you are free for example to add ML comments preceding the create_module invocation. Without fields filled in, the class declaration template should look like:


where [var] is a text slot for the variable name, and [type] is a term slot for the corresponding type of the variable. If there are no parameters, just leave the empty text sequence in this slot.

This has an extra term slot for an example of the projection function for that field. Initially, leave the term slot empty. Enter in the [var] slot the name of the field. The name of the projection function will be the name entered here with a suffix of the short module name. The type of a field can refer to constant types, the inhabitants of earlier fields or parameters.
Since the mlbd or mlbde terms are embedded in a text sequence, you can insert linebreaks in the sequence, by simply getting a text cursor in the sequence and typing RETURN .
Here is an example of a class definition that has been instantiated according to the procedure given so far:



Here a couple of abbreviated display forms are defined for the the module
type, one of which hides the level expression in the case that it is
simply the level variable
i. Standard notation is chosen for the
carrier, and the action is denoted by a `
' character. To
avoid clutter, a display form for the action is defined that hides the
instance of the
action_set module. This can nearly always be
determined from context.
Fill in the example slots of the mlbd terms with examples
of the relevant projection functions, operating on the
prototypical element declared in the uppermost example slot. In
the example, the terms
|s| and
s could be used.
With the given display form changes, and example terms, the final version of the example class definition looks like:

Examples of class definitions can be found in many of the algebra theories.