Bend languageexperimental
Pure, affine, dependency-typed: Bend compiles to native CPU and GPU code, and its checker proves the laws stated beside the code, so a program and its correctness proof live in one file.
Overview
Bend is a pure, statically typed language whose checker is also a proof assistant, in the tradition of Lean. Programs and their proofs live together: a law states a fact, a definition discharges it, and the compiler emits native CPU and GPU code that spreads independent calls across every core.
Code
import Base
def main() -> String:
+a = (6 * 7 : U32) # `+` may be copied; operators are Base names
b = U32.to_nat(a) # conversions are T.to_x and T.from_x
U32.show(a) ++ " = " ++ Nat.show(b)
import Base
def sum(xs: List<U32>, acc: U32) -> U32:
match xs:
case Nil{}:
acc
case Con{h, t}:
sum(t, (acc + h : U32)) # a smaller input: termination
import Base
def adder(k: U32) -> U32 -> U32:
x => (x + k : U32) # a closure captures k
def twice(~f: U32 -> U32, x: U32) -> U32:
f(f(x)) # `~` substitutes at compile time
def pow2(+n: Nat) -> U32:
match n:
case 0n:
1
case 1n+p:
a b = pow2(p) pow2(p) # parallel call
(a + b : U32)
def main() -> IO(Unit):
add2 = adder(2) # a closure, applied below
do IO<Unit>: # effects live in an IO monad
IO.print(U32.show(add2(40)))
IO.print(U32.show(twice(~(x => (x + 1 : U32)), 40)))
IO.print(U32.show(pow2!(20n))) # `!` runs on the GPU
import Base
law add_zero:
for x: Nat
{Nat.add(x, 0n) == x : Nat}
def add_zero(x):
match x:
case 0n:
{==}
case 1n+p:
%add_zero(p) : {1n+Nat.add(p, 0n) == 1n+_ : Nat}
{==}
Distinctive traits
- Affine by default, resource-aware like Rust: a value has one owner, so a match frees the node it opens and no garbage collector runs.
- Laws and proofs share one file: a
lawstates a fact, adefof the same name proves it. - Parallel calls are the idiom: an independent pair forks, and
!sends the whole subtree to the GPU. - Dependent types without universes:
Type : Typeholds, because running code may not copy a function - what Coq forbids for consistency. - Termination is checked, not assumed: recursive calls must consume a smaller part of their input.
- One C file per program is both the CPU binary and the GPU kernel, so one source runs on either chip.
Status
Young but fast-moving: Bend 2.0.39 (October 2026) ships under Apache-2.0 with Python-shaped syntax and C, Metal, CUDA and JavaScript targets. The type theory is mechanized in Lean, but the checker itself is unproven, and Windows is unsupported.
History
Started in 2023 as HVM-Lang, an intermediate representation for the HVM runtime; it took the name Bend in May 2024 and shipped to crates.io as bend-lang. Bend 2 is a ground-up rewrite that carries no Bend 1 programs over: the interaction-net runtime was dropped for a flat, stackless evaluator, and the type system became an affine dependent type theory.
Sources & references
- Official sitebend-lang.com
- BendTT: An Affine Dependent Type Theory (Higher Order Company)github.com
- BendRT: A Parallel Runtime for CPUs and GPUs (Higher Order Company)github.com
- Bend Guide - the language reference, also printed by `bend guide`github.com
- Bend 2 - repository README, demos and releasesgithub.com
- BendTT kernel - its Lean 4 formalization, used by `bend --verdict`github.com
- Bend 1 - the original massively parallel language, now supersededgithub.com
- Bend: a high-level language that runs on GPUs (via HVM2) - announcement, 17 May 2024news.ycombinator.com
- Hubhub.bend-lang.com