Modules - an extremely simple approach

(Rien) #1

I do not believe I have enough language inside to actually propose a solution. Still I would like to show what I think is the most simplest and flexible way to create modules.

Introduce the ‘module’ keyword to define a module.

module <MyModule>

To create an empty lexical module named “MyModule”:

module MyModule

To create content for the module define types/functions/variables/protocols etc using the module name with a dot notation:

var MyModule.myVar: Int

Defines a variable at the module level that can be referred to by “myVar” inside the module, and by “MyModule.myVar” outside the module.
Same for functions, classes, protocols etc.

To create a submodule:

module MyModule.SubModule

To create a sub-sub module:

module SubModule.SubSubModule

If no module definition is present, the default module name is the name of the project.

Defining a module with the same name as the project is allowed, but does not create a new module, it simply refers to the default module.

Visibility (access) is created by:

import <moduleName>

Access level (capability) must be defined by other means (preferably the mechanism proposed by Matthew)