A Tour of Morfa

Modules

Morfa code can be organized into modules. Every module resides in a separate file, named and placed according to the module name. The module is declared at the beginning of the file with a module statement. For a module placed in a file my_package/my_subdir/my_file.morfa, the statement would be:

module my_package.my_subdir.my_file;

public func mуFunction1(): void
{}

public struct MуType1
{}

Note that public access modifier must be applied for symbols to be visible in the importing module. To import my_file do:

import my_package.my_subdir.my_file;

unittest
{
    myFunction1();
    var variable = MyType1();
}

On encountering such import statement, Morfa searches following locations for the file my_package/my_subdir/my_file.morfa:

TODO

To import symbols from a module selectively use ::

import my_package.my_subdir.my_file: myFunction1, MyType1;

To force recursive importing of module's dependencies you can use public import:

module my_package.whole_package;
public import my_package.my_subdir.my_file;

To import symbols and require fully qualified names use static:

static import my_package.my_subdir.my_file;

unittest
{
    my_package.my_subdir.my_file.myFunction1();
    var variable = my_package.my_subdir.my_file.MyType1();
}

To import and rename symbols use =:

import shortcut = my_package.my_subdir.my_file;

unittest
{
    shortcut.myFunction1();
}

import shortcut2 = my_package.my_subdir.my_file : Renamed = MyType1;

unittest
{
    var variable1 = Renamed();
    var variable2 = shortcut2.MyType1();
}