Learn · 01
What is Ochre?
An introduction to Ochre — a statically typed, general-purpose programming language written in Rust with Copy-on-Write safety, colorless concurrency, and Cranelift native compilation.
Ochre (.och) is a statically typed, general-purpose programming language written in Rust. It is designed to combine the approachable, low-ceremony ergonomics of TypeScript and Go with the compile-time safety guarantees of Rust — packaged inside a single self-contained binary.
What Makes Ochre Different
Most languages force an early trade-off between fast iteration, static safety, and predictable runtime behavior:
- No
null, no uncaught exceptions: Optionality is modeled withT?(Some(v)/None), and fallible operations returnT!E(Ok(v)/Err(e)). You propagate errors with?or provide defaults with??. - Deep immutability + Copy-on-Write (
letvsvar): Bindings are immutable by default. Mutablevarcollections use thread-safe Copy-on-Write (Arc) value semantics, so aliased snapshots never mutate unexpectedly — without needing lifetime annotations. - Colorless concurrency: Spawn parallel work with
spawn { ... }and exchange typed messages overChannel<T>without splitting your codebase intoasyncand non-asyncfunctions. - One binary, complete toolchain:
ochreships with the bytecode VM, Cranelift AOT compiler (ochre build), formatter (ochre fmt), test runner (ochre test), project scaffolder (ochre init), REPL (ochre repl), and Language Server (ochre lsp).
A Quick Taste of Ochre
Run this interactive example right in your browser using Ochre's WebAssembly runtime:
struct TaskItem {
title: Str,
done: Bool,
}
impl TaskItem {
fn label(self) -> Str {
let icon = if self.done { "✓" } else { "○" }
return "{icon} {self.title}"
}
}
fn main() {
let tasks = [
TaskItem { title: "Learn Ochre syntax", done: true },
TaskItem { title: "Build a JSON API", done: false },
]
for item in tasks {
println(item.label())
}
}
Expected Output
✓ Learn Ochre syntax
○ Build a JSON API
How This Documentation Is Organized
| Area | Best For |
|---|---|
| Learn | Reading chapter-by-chapter to build a mental model of Ochre from scratch. |
| Guides | Building complete CLI tools, JSON REST APIs, concurrent workers, and native binaries. |
| Reference | Looking up exact syntax, operators, built-ins, CLI flags, and diagnostics. |
| Internals | Understanding how Ochre's compiler, bytecode VM, CoW memory, and Cranelift backend work. |
Exercise
Modify the runnable example above to add a third TaskItem with done: true and print the total number of tasks using len(tasks).
Show Solution
struct TaskItem {
title: Str,
done: Bool,
}
impl TaskItem {
fn label(self) -> Str {
let icon = if self.done { "✓" } else { "○" }
return "{icon} {self.title}"
}
}
fn main() {
let tasks = [
TaskItem { title: "Learn Ochre syntax", done: true },
TaskItem { title: "Build a JSON API", done: false },
TaskItem { title: "Write unit tests", done: true },
]
for item in tasks {
println(item.label())
}
println("Total tasks: {len(tasks)}")
}