[swift-evolution] Modules - an extremely simple approach

Rien Rien at Balancingrock.nl
Mon Mar 6 08:34:11 CST 2017


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)


Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: http://github.com/Balancingrock
Project: http://swiftfire.nl





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170306/7f2f1dea/attachment.html>


More information about the swift-evolution mailing list