Skip to content

Modules and imports

Modules let a package split definitions across source files. Declare a child module in the parent:

ligare
mod math
use math::add

pub def main : IO () :=
  let _ = add 1 2 in ()

The declaration above loads src/math.lig when it is in the package entry module's directory. src/math.lig can export:

ligare
pub def add (left right : int) : int := left + right

Only public definitions and modules are visible outside their defining module. Private helpers can be used freely inside the module that defines them.

Nested modules

Directories use a mod.lig file to declare child modules:

text
src/
├── main.lig
└── data/
    ├── mod.lig
    └── nat.lig

src/data/mod.lig can contain pub mod nat, and the entry file can import data::nat::value.

Standard library and dependencies

The standard library is addressed as the std package:

ligare
use std::data::nat::Nat
use std::io::print_line

Other packages use the same qualified path form after being declared in ligare.toml. Import trees support aliases and grouped names:

ligare
use math::add as plus
use data::nat::{Nat, zero}

The compiler and ligls use the same module graph and visibility checks, so a name accepted by the editor should follow the same package boundaries as a compiler invocation.