Modules
Split your code across files with import and export.
Creating a Module
src/math_utils.wyn:
wyn
export fn square(x: int) -> int {
return x * x
}
export fn cube(x: int) -> int {
return x * x * x
}Importing
src/main.wyn:
wyn
import math_utils
fn main() -> int {
println("5² = ${math_utils.square(5)}")
println("3³ = ${math_utils.cube(3)}")
return 0
}Modules are resolved relative to the importing file's directory.
Selective Imports
wyn
import { square, cube } from math_utilsExporting
Use export before any top-level declaration:
wyn
// Export functions
export fn add(a: int, b: int) -> int { return a + b }
// Export structs
export struct Point { x: float, y: float }
// Export enums
export enum Color { Red, Green, Blue }
// Export variables
export var VERSION = "1.0"Project Structure
my-project/
├── wyn.toml
├── src/
│ ├── main.wyn # entry point
│ ├── utils.wyn # import utils
│ └── models.wyn # import models
└── tests/
└── test_main.wynExample: Multi-file App
src/utils.wyn:
wyn
export fn greet(name: string) -> string {
return "Hello, ${name}!"
}
export fn square(x: int) -> int {
return x * x
}src/main.wyn:
wyn
import utils
fn main() -> int {
println(utils.greet("World"))
println("5² = ${utils.square(5)}")
return 0
}