2 Building Applications

2.2 Expressing source dependencies

To allow efficient compilation of the source files that make up an application, there must be some way to express dependencies between the files. MLWorks accomplishes this by extending Standard ML with an additional reserved word, require, which can be used in source files to make a top-level declaration of the form

require "<source-file>";

This tells the compiler that the present file uses values or functions defined in <source-file>, which should therefore be compiled first.

The require reserved word takes a single string argument, which is the name of an MLWorks unit (for program units see Section 2.4; for the moment, you can think of a unit name as being the name of a source file without the .sml extension). Any require declarations must be at the start of the file, before any other top-level declarations, and the argument must be a string constant, not just an ML expression of type string.

The effect of a require declaration is to import the declarations from the specified file into the current file. For example, suppose you have three files, xval.sml, yval.sml and sumxy.sml, all in the same directory, as follows:

Figure 2.1 A program comprised of three files.

Then the effect of the file sumxy.sml is to bind the identifier answer to the value 15.

Note: A file may use declarations from files it imports with require, but this relation is not transitive. Suppose you change xval.sml to require another file, zval.sml, to compute its value of x:

Figure 2.2 Another dependency is introduced.

Then sumxy.sml could still use the value of x, but not the value of z from zval.sml, as it does not explicitly require the latter file. In this respect, the MLWorks require extension is rather like the ML construction

local <declarations> in ... end


MLWorks User Guide (UNIX version 1.0) - 3 DEC 1996

Generated with Harlequin WebMaker