hd-lang

Compiles to WebAssembly

Rustic Effects on Pythonic Goland.

A statically typed, indentation-based language that compiles to WebAssembly, built for code that AI writes and humans review. hd is experimental: the language and its standard library still change.

Cheap · Scalable · Fast

Built for agents · daily metrics →

01 · Single-agent development cost

How cheaply does one agent get a correct program?

Measures

Compile and test latency is agent wait time; clear, short, well-placed diagnostics and fix-its that resolve mistakes are fewer retries and fewer tokens.

How hd gets there Explicit signatures let the checker skip dependency bodies, and checking is incremental per module. Diagnostics are compact, with JSON fix-its. Tests, property tests, and require/ensure contracts are built in.

02 · Agent scalability

How much useful work do N agents do on one machine?

Measures

CPU, memory and disk per check, startup, behaviour under concurrency, and caches that are shared, bounded and safe to write at once.

How hd gets there Check results and compiled code are cached by content and shared across processes, and std is checked once, inside the binary. A program reaches the host only through the capabilities it is granted.

03 · Artifact quality

How good is the program the agents produced?

Measures

The user's program, not the compiler: test speed, runtime against Node, allocations, binary size, host-call and serde cost, memory over time.

How hd gets there Code is generated per value layout, suspension compiles to state machines, and only reachable code goes into the Wasm module. Time, randomness, and I/O sit behind capabilities, so a test can fix them.

The core

A taste: algebraic effects in orbit

Three plain features stand in for an effect handler runtime. Walk through them in order.

Requirements declare

The signature lists everything welcome! may touch: mail and the clock.

fn welcome!(email: string) -> void $ Mailer + Clock: # ← sends mail, reads the clock
    mailer := $.use(Mailer)
    mailer.send!(email, "Welcome at ${$.use(Clock).now()}")

Elsewhere, only the body tells you it reads the clock or sends mail.

Run the full example

Providers handle

A test installs a fake mailer and a fixed clock for one block.

it("welcome mails the user at a fixed time, no mocks"):
    outbox := box(Outbox { sent: [] })
    $.with(Mailer=outbox, Clock=epoch()): # ← fakes, for this block only
        welcome!("ada@example.com")

Python: mock.patch or a DI container. Leave a provider out in hd and it does not compile.

Run the full example

! suspends

page! suspends, so its name says so. join! runs both fetches at once and joins them.

fn page!(id: i32) -> string $ Clock:
    let (profile, orders) = join!(fetch_profile(id), fetch_orders(id)) # ← both at once
    "${profile.name} has ${orders.len()} orders"

JavaScript: async spreads to every caller, and a forgotten await still compiles.

Run the full example

Typed derivation

Behavior derived from your types

Declare serialization, validation, and schemas on the type. Libraries derive them in plain hd from its fields.

  • @derive(Trait)a trait implemented from the fields

    Each derivable trait has a template: an ordinary impl in plain hd over the compiler's typed walk of a type's fields, written once by its library. Here std's Serialize and Deserialize let JSON and the host boundary read and write User.
  • impl Trait by Structurea derive written out, with settings

    @derive(X) means this block with an empty body. Write the block when the derive needs settings: here Validate takes a rule for each field, email = [email()], and a failure names its path, $.email.
  • @fact(...)a typed value on a type or a field

    A fact is checked like any other value, and only a template that looks for it reads it. Here a Table trait, ordinary library code, reads @column to name the first column user_id.

One type, three derivations

@derive and a by Structure block read the type's fields. No macros, no codegen.

@derive(Serialize, Deserialize, Table)
struct User:
    @column("user_id") # ← a typed fact that only Table reads
    id: i64
    email: string

impl Validate for User by Structure:
    email = [email()]
hd run
SELECT user_id, email FROM users
{"id":7,"email":"ada@example.com"}
$.email: must be a valid email address

Run the full example

Standard library

A standard library for getting it right

Its effects show in your signatures, and it ships a fake for each one. Property tests and contracts check the cases you would not think to write.

Effects in every signature

read_text!, write_text!, and now() each carry a requirement, so stamp! must list them. Drop Clock from the row and hd check stops at now() with missing-requirement.

fn stamp!(path: Path) -> Result[void, FsError] $ FsRead + FsWrite + Clock: # ← files and the clock
    text := read_text!(path)?
    write_text!(path, "${now()} $text")

Python: open() and time.time() appear in no signature, so only the body tells you what a function touches.

Run the full example

A fake for every capability

MemoryFs and ManualClock ship with std. The test touches no disk and no wall clock.

it("stamps a note in memory at a fixed time"):
    files := MemoryFs::new()
    _ := files.write_text!(Path("note.txt"), "tea")
    $.with(FsRead=files, FsWrite=files, Clock=epoch()): # ← no disk, no wall clock
        assert(stamp!(Path("note.txt")).is_ok(), reason="stamped")
    assert_equal(files.read_text!(Path("note.txt")).unwrap_or(""), "1970-01-01T00:00:00Z tea")

Same result on every run, on every machine.

Run the full example

Property tests from a derive

@derive(Arbitrary) makes the inputs. It caught a bug two hand-picked cases missed.

@derive(Arbitrary, Debug, Eq)
struct Money:
    cents: i32

it_prop("parse undoes print", prop=round_trips) # ← 100 generated Money values
hd test, on the first version of print
property test "parse undoes print" shrunk input Money { cents: -1000 };

Run the full example

Contracts: require, ensure

require checks the input and ensure checks every return, in debug and test builds.

fn withdraw(balance: i64, amount: i64) -> i64:
    require("the amount must be positive"):
        amount > 0
    rest := balance - amount
    ensure("an account is never overdrawn"): # ← checked at every return
        rest >= 0
    rest

Run the full example

Start building with hd

hd installs from source with the Rust toolchain, and programs run on Node or wasmtime.

git clone https://github.com/HerringtonDarkholme/hd-lang
cd hd-lang
cargo install --path crates/hd_cli --profile dist --features dist