Coming from Rust, Kotlin, or Lean
Clever draws deliberately from three traditions: Kotlin's surface ergonomics, Rust's ownership discipline, and Lean's machine-checked proofs. This Rosetta Stone maps familiar mental models — and highlights the subtle differences that trip people up on day one.
Coming from Rust
| Rust | Clever | Key difference |
|---|---|---|
let x = ...; let mut y = ...; |
val x = ...; var y = ...; |
Same semantics; Kotlin keywords. |
fn f(a: &T, b: &mut U) |
fun f(a: &T, b: &mut U) |
Call sites borrow implicitly: write f(x, y), not f(&x, &mut y). |
struct S<'a> { s: &'a [u8] } |
Disallowed — store (offset, len) or owned Bytes |
Borrows are second-class: no lifetimes, no stored or returned &T. |
x.clone() |
x.share() (for heap values) |
O(1) refcount increment; copy-on-write on mutation if rc > 1. |
a.wrapping_add(b) |
a +% b |
Plain +, -, * always trap on overflow, even in optimized builds. |
Option<T>, Result<T, E>, ? |
T?, Result<T, E>, ?, ?:, ?. |
Kotlin null-safety ergonomics (?:, ?., smart casts) + Rust ?. |
match x { ... } |
when (x) { ... } |
Exhaustive; is Variant -> smart-casts x to access variant fields. |
trait Foo, impl Foo for Bar |
trait Foo, impl Foo for Bar |
Traits can include laws; resolution is coherent with no backtracking search. |
#[derive(PartialEq, Eq, Ord)] |
@derive(Eq, Ord) |
Plain records/enums get Lean-proven Eq.lawful automatically. |
BTreeMap / HashMap |
Map<K, V> (B+tree) / std HashMap |
Built-in Map is ordered by default for deterministic iteration. |
rayon / tokio |
par for / suspend fun + scope + spawn |
Built into the language with deterministic clever sim replay. |
std::fs::read(...) anywhere |
Must receive fs: &mut Fs from main(io: Io) |
Zero ambient authority; dependencies cannot touch I/O without a passed cap. |
build.rs / Cargo.lock |
Zero-cap const fun / clever.lock |
No install scripts; clever.lock pins the reachable trust surface. |
Two Common Rust Habits to Adjust
- Records are value-immutable: you cannot write
r.x = 5directly on adatarecord field; user = r.copy(x = 5), or mutate elements ofArray/Buf/Bytesvia&mut. - No returning slices: instead of returning
&[u8]from a parser, return(offset: U64, len: U64)spans into the caller's&Bytes.
data Span(val offset: U64, val len: U64)
export fun firstLineSpan(b: &Bytes): Span {
for (i in 0u64 until b.len) {
if (b[i] == 10u8) { return Span(0u64, i) }
}
Span(0u64, b.len)
}Coming from Kotlin
| Kotlin | Clever | Key difference |
|---|---|---|
val / var, fun, data class, when, T?, ?., ?:, !!, smart casts |
Nearly identical syntax | Feels immediately familiar! |
sealed class / sealed interface |
enum with payload variants |
Value types, no heap vtables or inheritance hierarchy. |
Int / Long (32/64-bit wrapping, signed) |
U8..U128, I8..I128 |
Explicit widths and signedness; checked overflow by default (+% wraps). |
| Garbage collector + shared object references | Affine ownership + .share() CoW |
Passing a Bytes/Buf/String/Map by value moves it; borrow with & or &mut, or duplicate explicitly with .share(). |
try / catch exceptions |
Result<T, E> + ? (and traps for bugs) |
Recoverable errors are values; bugs (OOB, overflow) trap deterministically. |
suspend fun + coroutineScope + async/await |
suspend fun + scope + spawn/await |
Same structured concurrency mental model, plus deterministic clever sim. |
| Reflection / annotations at runtime | Compile-time @derive, const fun, module |
Zero runtime reflection overhead; predictable AOT code size. |
Two Common Kotlin Habits to Adjust
- Explicit borrows on read-only parameters: write
fun inspect(s: &String)rather thanfun inspect(s: String)unless you want the function to consume (move) the string. - Literal suffixes when needed: integer literals infer from context when unambiguous, and accept explicit suffixes (
0u64,10u32,-1i64,1.0f32). Byte literals useb"abc"or hexx"0102ff".
Coming from Lean 4
| Lean 4 | Clever | Key difference |
|---|---|---|
def (total) / partial def |
fun (total, measured loops) / partial fun |
Clean split between logic fragment (visible to proofs) and program fragment. |
theorem ... := by ... |
law ... proof by bv / script / proof by lean: |
Laws live beside systems code; bv/scripts run in Clever's fast compiled kernel, Lean is the escape hatch. |
UInt64 (wrapping) / Nat (arbitrary) |
U8..U128, I8..I128 (checked by default) |
Traps are modeled as Except Trap α in the generated Lean model (clever lean). |
StateM / ST for mutation |
&mut T parameters |
Compiles to in-place restrict pointers in C, elaborates to pure state passing in proofs! |
IO monad |
Explicit capabilities (Io, Out, Fs, Net, Clock, Rng) |
Capabilities are modeled as pure state/oracle transitions in the Lean model. |
#eval |
clever run / proof by decide |
Reference semantics in Clever/Flow/Interp.lean, differentially tested against C, Wasm, JS, Lean, and Metal. |
bv_decide (adds Lean.ofReduceBool axiom) |
proof by bv (LRAT certificate checked by Clever kernel) |
Audited proof by lean: theorems must use only propext, Classical.choice, Quot.sound. |
Two Common Lean Habits to Adjust
- Short-circuiting preconditions in laws: Clever has no
→implication operator in expressions; write!pre || claim(for example,a >= P || add(a, b) < P). Because||short-circuits,claim(including non-trapping) is only required whenpreholds. - No
Natin Clever source: state non-overflowing natural-number specs by widening operands toU128(e.g.,(a.toU128() + b.toU128()) % P.toU128()), then translate toNatwithBitVec.toNatinsideproof by lean:when needed.
fun safeInc(x: U8): U8 = x + 1u8
law safeInc_spec(x: U8): x == 255u8 || safeInc(x).toU16() == x.toU16() + 1u16
proof by bv