Lake

The Lake Programming Language

Lake is a process-oriented programming language built around machines, branches, and state transitions.

Programs in Lake are composed of machines — lightweight processes that define behaviour through pattern-matched branches. Branches are dispatched both by the types of arguments and by literal guards on those arguments. Machines communicate by spawning new processes, by sending messages to a pid, or by transitioning their own state via self(). A cooperative scheduler manages concurrent execution.

@rt(rt_write)

counter is {
  0 i64 -> { rt_write(1 "done\n" 5) }
  n i64 -> { self(n-1) }
}

main is {
  _ -> {
    counter(5)
    counter(3)
    counter(7)
  }
}

This program spawns three independent counter processes that run concurrently. Each one decrements until it reaches zero and prints done.

Notice the two branches of counter. The first matches when the argument is exactly 0. The second binds whatever else comes in to n. There is no if/else here — the dispatch is the conditional.

§Key ideas

  • Machines are the core abstraction — each machine call spawns a new cooperatively-scheduled process.
  • Branches dispatch on both the argument's type and any literal guard. Matching is O(1).
  • self(args) transitions the current process to a new state — it does not allocate or schedule.
  • Spawn-by-call — calling any machine other than self spawns a new concurrent process.
  • Messages — calling a value of type pid sends a message to that process; wait { ... } receives.
  • Cooperative scheduling — each process runs a quantum of 256 reductions before yielding.

§More than processes

Around the process model Lake has grown a full static type system and a small but real ecosystem:

  • Records and enums — product and sum types, with exhaustiveness-checked when.
  • Generics — monomorphised, zero-cost (Vec[T], Box[T], unbox[T]).
  • Protocols — interfaces/traits with static dispatch and no vtables; even [] is the Index protocol.
  • Error handling — no exceptions, no null: Option[T], Result[T E], and panic with a source location.
  • Standard libraryVec, String, IntMap, SHA-256/HMAC/PBKDF2 — written in Lake over direct syscalls.
  • Packages & toolinglakeup (toolchain), house (build + registry), and pg, a pure-Lake PostgreSQL client.

Together these let you write a native, database-backed web service entirely in Lake — see the URL-shortener in Packages & tooling.

§Status

Lake is in active development. The compiler targets x86-64 Linux and emits self-contained native binaries — no virtual machine, no garbage collector. This guide tracks the features currently in the compiler; anywhere a fence is marked lake-run you can press Run and see the output.