examples

Examples that cross more than one feature.

Hale becomes interesting when ownership, messaging, placement, failure, and contracts meet. These are compact views of those system shapes; the linked guide chapters carry the full programs and explanation.

sharded job queue

Let the topic own the routing table.

A keyed topic sends each job only to the worker for that shard. The handler does not receive every job and filter by hand.

Read the job-queue tutorial →
workers.hl
topic JobReady { payload: Job; keyed_by queue_id; }

locus Worker {
    params { queue_id: Int = 0; }

    bus {
        subscribe JobReady as perform
            where key == self.queue_id;
    }

    fn perform(job: Job) {
        // this worker receives only its shard
    }
}
production.hl
main locus Production {
    bindings {
        JobReady: unix("/run/jobs.sock");
    }

    on_failure(t: std::bus::UnixTransport,
               err: ClosureViolation) {
        restart(t);
    }
}

supervised transport

A broker connection is part of the lifecycle.

Bind the topic in main. If the transport loses its peer, the binding locus fails structurally and the owning application decides whether to restart it.

Read across binaries →

causal boundary

State what may influence a subsystem.

The dependency set is checked transitively through the bus graph. A republisher cannot quietly launder an undeclared source into this locus.

Read effects and causality →
risk-view.hl
@effects(depends: {Orders, RiskConfig, RiskSnapshot})
locus RiskView {
    bus {
        subscribe RiskSnapshot as update;
        subscribe RiskConfig as configure;
    }
}
score.hl
@no_block @no_syscall @deterministic
@budget(alloc_per_call = 0)
fn score(sample: Sample) -> Float {
    return sample.weighted_score();
}

certified hot path

Make the performance assumption reviewable.

This path is not merely intended to avoid the kernel, waiting, and allocation. The compiler follows its callees and rejects the build when the promise stops being true.

Read effects and contracts →

Try the full progression.

The browser tour moves from ordinary functions to loci, typed topics, supervision, and deployment without changing tools.

Open the playground