Skip to content

Language reference

Modules and exports

Organize source into explicit modules and imports.

Each .k file is a module. Declarations are private unless exported. Imports name exactly which declarations enter the current scope, with optional aliases. Relative imports include their .k extension.

Export a function

In math.k:

kalandra
export fn double(value: int) -> int:
  value * 2

In main.k in the same directory:

kalandra
from "./math.k" import double as twice

fn main() -> int:
  twice(21)
bash
kalandra-check main.k
kalandra main.k -o program
./program

The executable displays 42. The import path is relative to main.k, not to the terminal's working directory. Keep both files in the same directory for this example.

Export types deliberately

Record, enum and error declarations can be exported and imported. Aliasing preserves their nominal identity rather than creating a new type. A helper continues resolving its own private names in its declaring module; importing it does not expose all of that module.

Re-export a public surface

An explicit re-export lets a library entry expose selected functions or types from internal modules. Re-exports preserve the original declaration identity and helper scope. Use a small public entry instead of requiring callers to know the internal directory layout.

Use a package name

A bare import such as from "geometry" import total refers to an explicit package mapping or installed dependency. The compiler does not guess a module from your working directory or fetch a missing library while building.