Why Haze
Design pressures behind Haze.
Contents
Most programs state their important rules in comments, validation code, and tests. These records drift apart and cover only the cases the author considered. Haze makes function obligations part of the signature, valid states part of the type declaration, and failure a value returned to the caller.
Principles#
| Principle | Consequence |
|---|---|
| Contracts are executable | pre, post, named contracts, type invariants, and loop invariants are checked by the compiler where possible and by runtime checks otherwise. A failed contract is either a compile-time error or a runtime abort; only checked construction returns a value. |
| Invalid states are unrepresentable | Refinement types, sum types, Option, and Result make invalid values impossible to construct. |
| Memory is automatic | Lists, records, sum values, closures, and byte buffers are reclaimed by a tracing collector. There is no manual free, reference counting, or borrow checker. |
| Functional composition with imperative control flow | Haze has for, mutation, and early return, along with first-class functions, method-call syntax, pattern matching, and collection pipelines. |
Contracts#
A contract is a boolean expression over a function's parameters and result. The compiler evaluates contracts with constant arguments, rejects violations it can prove, and emits runtime checks for the rest. A public function should state its domain: a division function requires a nonzero divisor, an indexing function requires an in-range index.
Failure#
There is no unwrap, no exceptions, and no implicit panic path for expected failures. Operations that can fail return Result[T, E]; operations that can be absent return Option[T]. Callers recover values with match or is. Checked construction either produces a valid value or returns an error.
Memory#
Managed values are allocated on the Haze heap and reclaimed when unreachable. The compiler emits root maps at collection points, so the collector does not scan registers. Application code does not manage memory unless it crosses into C.
Style#
The following principles explain most language choices:
| Principle | Consequence |
|---|---|
| Prefer total functions | Model missing and failing cases in the return type. |
| Prefer narrow types | Use refinement and sum types to make invalid values impossible. |
| Prefer explicit obligations | Write preconditions and postconditions for behaviour callers depend on. |
| Prefer immutable data flow | Build new values; mutate only local accumulators. |
| Prefer composition | Use small pure functions and pipelines before control-flow machinery. |
| Prefer Haze over FFI | Cross into C only for capabilities the language does not provide. |
| Prefer evidence over assertion | Use tests for behaviour and contracts for invariants. |