A module declaration collects and packages declarations of adt, functions, data, constants and simple types, and creates an interface with a name that serves to identify the type of the module. The syntax is:
module-declaration:
identifier: module {mod-member-listopt};
mod-member-list:
mod-member
mod-member-list mod-member
mod-member:
identifier-list : function-type;
identifier-list : data-type;
adt-declaration;
identifier-list : con expression;
identifier-list : type type;
After a module declaration, the named identifier becomes the name of the type of that module. For example, the declaration:
Linear : module {
setflags : fn (flags : int);
TRUNCATE : con 1;
Vector : adt {
v : array of real;
add : fn (v1 : self Vector, v2 : Vector) : Vector;
cross :fn (v1 : self Vector, v2 : Vector): Vector;
dot : fn (v1 : self Vector, v2 : Vector);
make : fn (a : array of real) : Vector;
};
Matrix : adt {
m : array of array of real;
add : fn (m1 : self Matrix, m2 : Matrix) : Matrix;
mul : fn (m1 : self Matrix, m2 : Matrix) : Matrix;
make : fn (a : array of array of real) : Matrix;
};
};
is a module declaration for a linear algebra package that implements two adt's namely, Vector and Matrix, a constant, and a function setflags. The name Linear is the type name for the module, and it can be used to declare an object referring to an instance of the module:
linearmodule : Linear;Before the module can be used, it must be loaded, for example in the style:
linearmodule = load Linear "/dis/linear.dis";
if (linearmodule == nil) {
sys -> print("Can't load Linear\n");
exit;
}
The load operator is discussed more fully in Load expressions.