MODULE | Language | Program

A MODULE is a named namespace that holds declarations and nests to any depth.

The grammar of a single MODULE line:

A MODULE keyword can live inside MODULE , TYPE , and FUNCTION keywords, or at the Root.

A module nested directly inside another, opening a deeper namespace within it.

The outer module's name prefixes everything the inner one declares, so the innermost is named Code.Language.Json from anywhere else in the program.

A module inside a type acting as a pseudo-module, scoped under the type's dotted name.

The module nests beneath the type's dotted name, so the inner Result here is named Value.Parse.Result .

A module inside a function acting as a pseudo-module, scoped under the function's dotted name.

The module nests beneath the function's dotted name, prefixing everything it declares.

At the program's Root a module opens a root namespace — the outermost scope its members are named under.

With nothing above it, the module opens the outermost scope, and its name prefixes every member declared inside.

Declarations, in any order — and, as the one exception, NATIVE setup that runs at the module's start. No other running statements appear. Each kind below lives directly inside the module:

A nested module, scoping a deeper namespace within this one; modules nest to any depth.

A derived function declared in the module's namespace and called by its qualified name.

A type belonging to the module — a record of fields or a union of options, with its members and constructor scoped in this namespace.

A named constant in the module's namespace — a fixed value bound with a constant expression (a literal, or a type constructor applied to literals) and reached through the module's name. Unlike a LET in a body it is a declaration, not running code.

A per-target block of native host code that runs once at the module's start, whenever the module is used in a program — the module's setup on that platform. It is the only running code a module holds.

The same example, rendered to each target.

A module's members are declared with FUNCTION and TYPE , and nested MODULE s. Running statements such as STATE live outside a module, in the run body. Back to the language .

Recommended articles