Contents

Every Haze file is a module. There is no module declaration and no package manifest. The compiler loads the entry file, follows its use declarations, and checks the resulting module table.

Files and Module Names#

The entry module is named after the entry file's stem. A dependency is named by its path relative to the entry file's directory, with .hz removed. A file named core.hz inside a directory takes the directory's name.

File Module name when loaded from the entry directory
main.hz main (the entry module)
orders.hz orders
lib/pair_mod.hz lib/pair_mod
std/seq/core.hz std/seq
a/b/c/deeper.hz a/b/c/deeper

The module name qualifies symbols internally and in diagnostics. Two modules can define the same private helper without a collision.

Imports#

A use declaration names a module path. With braces it imports specific public names. Without braces it imports every public name as a wildcard. There is no aliasing.

use std/seq {map, filter, fold}
use std/env {args}
use orders

An explicit import makes the selected names available unqualified. A wildcard import makes all public names available. An explicit name takes precedence if both forms are present. If two wildcard imports export the same name, the first module in declaration order wins.

Module paths use / separators. Qualified access after loading uses ::, as in seq::fold(...).

Relative Imports#

A path may start with . or ... It resolves relative to the importing file.

use ./local_helper {helper}
use ../shared/types {Config}
use ../../modules/some_module {root_value}

use . resolves to ./core.hz in the importing file's directory; use .. resolves to ../core.hz. use ../deep resolves to ../deep.hz or ../deep/core.hz.

File Lookup#

For a module path p and importing file in directory d, the compiler tries d/p.hz, then d/p/core.hz. The first existing regular file wins.

<importing directory>/<module path>.hz
<importing directory>/<module path>/core.hz

Visibility#

Declarations are private by default. pub makes a top-level function, type, constant, contract, or trait visible to other modules. Trait methods and implementation methods may also be marked pub. An impl block is not public; the trait and target type determine whether the implementation is usable elsewhere.

const INTERNAL_LIMIT i32 = 100

pub type Order {
    id    i32
    qty   i32
    price i32
}

pub pure fn total(order Order) i32 => order.qty * order.price

Importing or qualifying a private name is an error. A wildcard import skips private names.

Standard Library#

The standard library lives under std/ in the hazelib directory next to the compiler. An import beginning with std/ is first looked up relative to the importing file, then under the standard library root.

use std/seq {map, filter, fold}
use std/env {args}
use std/fs {read_file, write_file}

Standard modules follow the same visibility and import rules as user modules. Consult their source for available names.

Entry Point#

The entry module must define main, which takes no parameters. Process arguments are available through the environment module as a List[str].

use std/env {args}

fn main() {
    for argument in args() {
        print(argument)
    }
}

The first element is the program path. Invalid UTF-8 arguments are omitted.

Tests#

A test "name" { ... } block is attached to its module. A normal compile ignores test blocks. hz test treats each file it is given as an entry module. Tests in imported modules are not run when the importer is compiled.

test "total multiplies quantity by price" {
    const order = Order { id = 1, qty = 3, price = 10 }
    assert total(order) == 30
}

See Tests.

Cycles#

Module loading is breadth-first and memoized by module name. A cycle does not produce a special diagnostic; the second request for an already loaded module is skipped. Declarations are still checked in their own module, so a cycle does not bypass visibility or type rules.

Module Boundaries#

Export the smallest surface callers need. Keep helpers private and let contracts define the obligations of exported functions. Types are nominal: two records with identical fields are different types.