Next: , Previous: Nested sub-modules, Up: Sub-modules


9.3.2 Separate sub-modules

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

     :- include_module Module1, Module2, ..., ModuleN.

Each of the named sub-modules 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. (For a module named ‘foo.bar.baz’, The University of Melbourne Mercury implementation requires the source to be located in a file named foo.bar.baz.m, bar.baz.m, or baz.m.) The separate source file must contain the declaration (interface) and definition (implementation) of the sub-module. It must start with a ‘:- module’ declaration which matches that in the ‘:- include_module’ declaration in the parent, followed by the interface and (if necessary) implementation sections, and it may optionally end with a ‘:- end_module’ declaration. (Note: the module names in the ‘:- module’, ‘:- end_module’, and ‘:- include_module’ declarations need not be fully-qualified. However, if the file name used for a particular module does not include all the module qualifiers, then the University of Melbourne Mercury implementation requires the module name in the ‘:- module’ declaration for that module to be fully qualified.)

The semantics of separate sub-modules are identical to those of nested sub-modules. The procedure to transform a separate sub-module into a nested sub-module is as follows:

  1. Replace the ‘:- include_module submodule’ declaration with the interface section of the sub-module enclosed within ‘:- module submodule’ and ‘:- end_module submodule’ declarations.
  2. Place the implementation section of the sub-module 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.