Next: , Previous: Nested submodules, Up: Submodules   [Contents]


9.3.2 Separate submodules

Separate submodules are declared using ‘:- include_module Modules’ declarations. Each ‘:- include_module’ declaration specifies a comma-separated list of submodules.

:- include_module Module1, Module2, …, ModuleN.

The module names need not be fully qualified.

Each of the named submodules in an ‘:- include_module’ declaration must be defined in a separate source file. The mapping between module names and source file names is implementation-defined. The Melbourne Mercury implementation requires that

The source file of a separate submodule must contain the declaration (interface) and definition (implementation) of the submodule. It must start with a ‘:- module’ declaration containing the fully qualified module name, followed by the interface and (if necessary) implementation sections, and it may optionally end with a ‘:- end_module’ declaration. (The module name in the ‘:- end_module’ declaration need not be fully qualified.)

The semantics of separate submodules are identical to those of nested submodules. The procedure to transform a separate submodule into a nested submodule is as follows:

  1. Replace the ‘:- include_module submodule’ declaration with the interface section of the submodule enclosed within ‘:- module submodule’ and ‘:- end_module submodule’ declarations.
  2. Place the implementation section of the submodule enclosed within ‘:- module submodule’ and ‘:- end_module submodule’ declarations in the implementation section of the parent module.

For example

:- module x.
:- interface.
:- include_module y.
:- end_module x.

is equivalent to

:- module x.
:- interface.
    :- module y.
    % interface section of module ‘y’
    :- end_module y.
:- implementation.
    :- module y.
    % implementation section of module ‘y’
    :- end_module y.
:- end_module x.

Next: , Previous: Nested submodules, Up: Submodules   [Contents]