next up previous contents
Next: 2.5 Name visibility Up: 2. The CM model Previous: 2.3 Invoking CM   Contents

2.4 Members of a library

Members of a library do not have to be listed in any particular order since CM will automatically calculate the dependency graph. Some minor restrictions on the source language are necessary to make this work:

  1. All top-level definitions must be module definitions (structures, signatures, functors, or functor signatures). In other words, there can be no top-level type-, value-, or infix-definitions.
  2. For a given symbol, there can be at most one ML source file per library (or--more correctly--one file per library component; see Section 2.6) that defines the symbol at top level.
  3. If more than one of the listed libraries or components is exporting the same symbol, then the definition (i.e., the ML source file that actually defines the symbol) must be identical in all cases.
  4. The use of ML's open construct is not permitted at the top level of ML files compiled by CM. (The use is still ok at the interactive top level.)

Note that these rules do not require the exports of imported libraries to be distinct from the exports of ML source files in the current library. If an ML source file $f$ re-defines a name $n$ that is also imported from library $l$, then the disambiguating rule is that the definition from $f$ takes precedence over that from $l$ in all sources except $f$ itself. Free occurences of $n$ in $f$ refer to $l$'s definition. This rule makes it possible to easily write code for exporting an ``augmented'' version of some module. Example:


  structure A = struct (* defines augmented A *)
      open A           (* refers to imported A *)
      fun f x = B.f x + C.g (x + 1)
  end

Rule 3 may come as a bit of a surprise considering that each ML source file can be a member of at most one library (see section 2.7). However, it is indeed possible for two libraries to (re-)export the ``same'' definition provided they both import that definition from a third library. For example, let us assume that a.cm exports a structure X which was defined in x.sml--one of a.cm's members. Now, if both b.cm and c.cm re-export that same structure X after importing it from a.cm, it is legal for a fourth library d.cm to import from both b.cm and c.cm.

The full syntax for library description files also includes provisions for a simple ``conditional compilation'' facility (see Section 7), for access control (see Section 8), and it accepts ML-style nestable comments delimited by (* and *).


next up previous contents
Next: 2.5 Name visibility Up: 2. The CM model Previous: 2.3 Invoking CM   Contents
Matthias Blume
2001-07-19