ES
Language GuideTypes & Modules

Modules & Selective Imports

Canonical module resolution, visibility (pub), selective from ... use imports, aliases, and multi-file projects in Wysna.

Wysna organizes code into explicit file-based modules with clear visibility boundaries and zero implicit global namespace pollution.


Import a standard library module or local relative file with import "<path>", optionally assigning an alias with as:

import "std/json"
import "std/text" as txt
import "./pricing.wysna" as pricing
fn main() -> unit {
let clean = txt.trim(" wysna ")
print(clean)
}

Both Seed and the Self-Hosted Native SDK support selective imports with from ... use, eliminating repetitive module prefixes and reducing token overhead by ~13–22% in dense code:

# Single symbol
from std.path use join
# Multiple symbols with trailing comma and local alias
from std.text use {
contains,
to_lower,
split as text_split,
}
# Local module import
from "./domain/quote.wysna" use {
Quote,
quote_total,
}

Declarations are private to their module by default. Mark functions, structs, enums, classes, interfaces, and exported tuple bindings with pub to expose them across module boundaries:

src/domain/pricing.wysna
let INTERNAL_CAP = 10000
pub struct LineItem {
pub sku: str
pub unit_price_cents: int
pub quantity: int
}
pub fn line_total(item: LineItem) -> int {
return item.unit_price_cents * item.quantity
}
pub let (DEFAULT_CURRENCY, DEFAULT_TAX_BPS) = ("USD", 1500)

Attempting to access a non-pub declaration from another module triggers compile-time diagnostic [W3002].

When building a library or framework, use pub import inside src/lib.wysna to re-export internal modules cleanly through a single entrypoint:

# src/lib.wysna — public library barrel
pub import "./router"
pub import "./middleware"
pub fn version() -> str {
return "1.0.0"
}

  • Standard Library (std/*): Always resolves against the installed SDK’s bundled stdlib/ root. The compiler rejects parent-directory traversal (..) and symlinks escaping the standard library directory, and never silently falls back to the current working directory.
  • Relative Imports (./): Resolve relative to the importing source file. Circular module cycles are rejected with [W1003].
  • Package Dependencies (pkg/<alias>/<module>): Install dependencies with wysna add <spec> (wysna.toml + wysna.lock) and import them anywhere via import "pkg/<alias>/<module>" or from "pkg/<alias>/<module>" use { ... }. Direct and transitive dependencies resolve automatically. See Packages, Libraries & Frameworks and Projects & Lockfiles.