Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Declarations

Grammar

dec ::= def_bind | type_bind | mod_bind | mod_type_bind | entry_bind
      | "open" mod_exp
      | "import" stringlit
      | "local" dec
      | "#[" attr "]" dec

Description

A Wyn module consists of a sequence of declarations. Declarations are processed in order, and a declaration may refer only to names bound by preceding declarations — forward references are not permitted.

The five binding forms — def_bind, type_bind, mod_bind, mod_type_bind, and entry_bind — bind values (including functions), types, modules, module types, and host-visible entry points respectively. Their syntax is detailed in the sections that follow.

Names bound by a declaration inside a module are visible to users of the module by default (see Modules); the local modifier suppresses this.

Declaration Modifiers

  • open mod_exp brings the names bound in mod_exp into the current scope. They are also re-exported through the enclosing module.

  • local dec binds the names defined by dec in the current scope but hides them from users of the enclosing module.

  • import "foo" is shorthand for local open of the module expression import "foo" (see Modules) — it pulls in another file’s exports without re-exporting them.

DISCREPANCY: The current compiler does not implement the local modifier or apply local-open semantics to plain import "foo". This visibility work is deferred for the first package manager, which treats every declaration as non-local. The intended behavior remains part of the language and is covered by ignored tests in wyn-core/src/resolve_imports_tests.rs.

  • #[attr] dec attaches an attribute to the declaration it precedes (see Attributes).