Production-quality AXIOM code. Copy, modify, ship.
module hello -- Every side-effect requires an explicit capability. -- 'requires IO' means this function can interact with the outside world. fn main() -> Result<Unit, IOError> requires IO { io.print("Hello, AXIOM!")? Ok(()) }
module shapes enum Shape { Circle(radius: Float<64>), Rectangle(width: Float<64>, height: Float<64>), Triangle(base: Float<64>, height: Float<64>), } -- Pure function: no capabilities required, no side effects. fn area(shape: Shape) -> Float<64> { match shape { Shape.Circle(r) => 3.14159 * r * r, Shape.Rectangle(w, h) => w * h, Shape.Triangle(b, h) => 0.5 * b * h, } } -- The compiler guarantees all variants are handled. -- Adding a new variant forces you to update every match.
module errors enum ParseError { InvalidFormat(msg: String), OutOfRange(value: Int<64>, max: Int<64>), } fn parse_port(input: String) -> Result<Int<16>, ParseError> { let value = input.parse_int() .map_err(|e| ParseError.InvalidFormat(e.message))? if value < 1 || value > 65535 { Err(ParseError.OutOfRange(value, 65535)) } else { Ok(value.to<Int<16>>()) } } -- Usage: the ? operator propagates errors up the call stack. -- You can never accidentally ignore an error in AXIOM. fn setup(port_str: String) -> Result<Config, ParseError> { let port = parse_port(port_str)? Ok(Config { port, host: "0.0.0.0" }) }
module parallel fn fetch_all(urls: List<String>) -> Result<List<Response>, NetError> requires Net, Async { -- TaskGroup ensures ALL spawned tasks complete before this scope exits. -- No fire-and-forget. No leaked goroutines. No orphaned promises. let group = TaskGroup.new() for url in urls { group.spawn(|| { net.http.get(url)? }) } -- All tasks run in parallel. Results collected in order. group.join_all() } -- Cancellation is cooperative and deterministic. -- If any task fails, the group cancels siblings and returns the first error.
module finance struct Money { amount: Decimal<18, 4>, -- 18 digits, 4 decimal places currency: Currency, } fn apply_tax(price: Money, rate: Decimal<8, 4>) -> Money { -- No floating-point rounding errors. Ever. -- 0.1 + 0.2 == 0.3 is ALWAYS true in AXIOM. Money { amount: price.amount * (1.0000 + rate), currency: price.currency, } } fn split_bill(total: Money, ways: Int<32>) -> List<Money> { let share = total.amount / ways.to_decimal() let remainder = total.amount - (share * ways.to_decimal()) -- First person pays the remainder (deterministic, auditable) let shares = List.fill(ways, Money { amount: share, ..total }) shares.update(0, |m| m { amount: m.amount + remainder }) }
module server use std.net.http.{ Server, Request, Response, Status } use std.json struct User derives Serialize, Deserialize { name: String, age: Int<32>, } fn main() -> Result<Unit, ServerError> requires Net, IO { let app = Server.new() .get("/", |_req| { Response.text("Welcome to AXIOM!") }) .post("/users", |req| { let user = req.body.parse::<User>()? io.print("New user: {user.name}")? Response.json(user, Status.Created) }) io.print("Server running at http://localhost:3000")? app.listen(3000) }
module driver -- Profile constraints are checked at compile time. -- This function can only be used in firmware or bare-metal targets. fn init_gpio(pin: Int<8>, mode: PinMode) -> Result<GpioHandle, HwError> requires Hardware profile Firmware | BareKernel { let reg = hardware.mmio.read(GPIO_BASE + pin.to<Addr>())? hardware.mmio.write(reg, mode.to_bits())? Ok(GpioHandle { pin, mode }) } -- Trying to call init_gpio from a web or server profile -- is a compile-time error, not a runtime failure.
Side-effect-free computations with guaranteed reproducibility.
Web servers, REST APIs, and microservices in AXIOM.
Bare-metal programming with compile-time safety guarantees.
Fixed-point math, ledger systems, and auditable computation.