Modules (roadmap #18a, #18b)

# main.tr
import "modules/geometry.tr" as geo     # `as` is optional: the default name is the file's stem
import "modules/stats.tr"

fn main():
  let shapes = [geo.Circle(1.0), geo.Rect(w: 2.0, h: 3.0)]
  print(geo.total(shapes))
  match shapes[0]:
    geo.Circle(r) => print(r)
    _ => print("not round")
# modules/geometry.tr
pub type Shape =
  | Circle(r: Float)
  | Rect(w: Float, h: Float)

fn square(x): x * x                   # private: only this file can use it

pub fn area(s): ...

How it works: each module's definitions are renamed to <module>.<name> and merged into one program before type checking, so the checker, all three engines and the tools work unchanged. A module's lines are numbered from k × 1,000,000 internally so every position stays unique and maps back to its file.

Local packages (35a)

A bare name imports a package listed in the nearest trine.toml (searched upward from the importing file):

# app/trine.toml
[package]
name = "app"

[dependencies]
geometry = { path = "../geometry" }     # ../geometry/lib.tr  (or a path ending in .tr)
import "geometry" as geo

Git dependencies, trine.lock and the shared build cache: see PACKAGES.md.

Capabilities per module (47a)

trine caps main.tr ends with one line per imported module: either "can't reach the outside world" or which of its functions take a Sys, a Dir or a function. A module has no authority of its own (there are no globals): it can use only what its importer passes to those functions. So reviewing a dependency's reach means reading those lines, not its code.

The store and the tools across modules (18c, 18d)