3.9. Modules

3.9.1. Top Level Modules

A module is a compilation unit. It is part of a package. It contains an implementation file <name>.al and an interface file <name>.ali.

A module consist of a use block and a series of declarations.

3.9.1.1. Use Block

The use block indicates which other modules are used by the current module.

use
    <mod₁>                  -- modules of the same package
    <mod₂>
    alba
        standard            -- some modules of package 'alba.standard' used
            natural         -- used modules of the package 'alba.standard'
            list
            array
            ...
        browser
            virtual-dom
            ...
        ...
    ...

The order of the used modules is not relevant. If a used module already uses some other modules publicly (i.e. uses it in its interface file), then the other modules are used implicitly by the current module. This avoids cluttering up the use block.

3.9.1.2. Declarations

A declaration block consists of zero or more declarations. A declaration is one of:

In a module interface functions and constants can be declared without definition. In that case the definition (or implementation) of a function / constant is not visible to the clients.

Inductive data types and their constructors can be declared in a module interface as constants without definition as well. In that case the user of the module does not know, that the type is an inductive type and cannot pattern match on objects of that type.

3.9.1.3. Interface and Implementation File

The implementation file of a module must implement all types, constants and functions declared in its interface file. If the interface file defines everything completely, then the implementation file is not necessary.

3.9.2. Inner Modules

An inner module is a module within a module. It has no use bock. Only implementation files can have inner modules.

Syntax:

module
    <declaration₁>          -- publicly visible declarations
    <declaration₂>
    ...
:=
    <declaration₁>          -- private definitions and implementations
    <declaration₂>          -- for the public declarations
    ...