#Modules

A source file communicates through explicit require and provide declarations. Requiring a file selects bindings from its public interface; it does not bring every definition into the caller's scope.

#Importing Source

This two-file project exports a function returning 42:

(require double:(Fn Int Int) from="./math.rig") (define answer:(Fn Int) answer=(fn do=(double 21))) (provide answer:(Fn Int))

from="./math.rig" is relative to the importing file, not the process working directory. The required name and exact type must match a provided binding. Dependencies are discovered from these declarations; there is no separate list of source files to keep synchronized.

This is a library project. Build it to export answer; it does not implement the WASI command interface used by rig run.

#Public and Private Bindings

Only provided bindings belong to the source module's public interface. A module may keep helpers and state private while exposing functions that use them. Re-exporting an imported binding preserves its defining identity; it does not copy its initializer into a new owner.

provide selects from the module's declarations regardless of where the provide form appears. Its entries are selections, not an initialization sequence. require is different: its entries become available sequentially, so an imported type may be used in a following annotation.

Source interfaces can expose overloads. A consumer selects the exact signatures it needs; imported functions still follow the ordinary overload rules.

Both forms belong at module scope, not inside a function, let, or quotation.

#Importing Types and Staged Values

Types are ordinary staged values, so they use the same interface mechanism as functions:

(require Point:Type_1 make_point:(Fn Int Int Point) from="./geometry.rig") (define total:(Fn Int) total=(fn do=(select (make_point 20 22) (fn x:Int y:Int do=(add x y))))) (provide total:(Fn Int))

Point is imported at Stage 1 and used to check the Stage 0 function signature. It is not a runtime type object. One require or provide form can contain different stages because each binding carries its own type and stage.

A source module can also provide a Stage 1 or Stage 2 function for a consumer at that stage.

#Reusing a Module at a Higher Stage

Use lift=1 to place a provider one stage higher. This project uses an ordinary double function at compile time and embeds the result into answer.

(require double:(Fn_1 Int_1 Int_1) from="./math.rig" lift=1) (define answer:(Fn Int) answer=(fn do=(inline (const (double 21))))) (provide answer:(Fn Int))

lift takes a nonnegative integer literal and defaults to zero. The entire source module moves together, including its annotations and dependencies. The import names the type at the selected stage. Separate require forms can select the same provider at different offsets, with separate initialization for each view.

Keep named public Component exports (provide ... as=) in the module that exposes the external interface. A lifted source module can expose its reusable implementation through unqualified provide.

#Initialization and Shared State

Selected source dependencies initialize at their bindings' stages, before the modules that use them. Repeated imports of the same module reuse that owning evaluation. Functions and quotations retain the defining module's static links rather than acquiring the caller's state.

Initializers remain eager even when their values are unused. Importing a module is therefore not a promise that only the selected function's effects will occur. Merely discovering an unrelated package, however, does not select or initialize it.

Syntax and Bindings describes source order and non-suspending static initialization.

#Source Interfaces and Component Interfaces

An unqualified provide is also used when building a public Component, but that artifact has a narrower boundary vocabulary than Rig source. Functions may be exported only when their parameter and result types can cross that boundary. Native closure values, fixed Strings, and arbitrary internal references are not public Component values.

provide ... as="..." implements a named external interface. Its contract must be complete and its callable exports belong to Stage 0. That does not restrict ordinary source exports at higher stages.

Package imports use the same require form with a pkg: reference. Named interface exports of a Component package are selected explicitly after #; a bare package import selects only root bindings. A contract-only reference such as wasi:cli/stdout@0.3.0 instead declares a host requirement. It does not search packages for an implementation.

Projects and Packages covers resolution and local overrides. WebAssembly Components explains external contracts and ownership. Getting Started supplies a complete WASI command using the same module forms.