Public release v1.8.0 · Spec v0.2.0-draft · Star on GitHub

Language

Compact surface that lowers to Rust. Prefer the tutorial for a guided tour.

At a glance

Comments: -- and nested {- -}. Interpolation: "hello {name}". Exponentiation: **.

Snippets

Short, copyable patterns. Guided tour: tutorial.

Struct + defaultstype
type ServerConfig = {
    host: str  = "127.0.0.1"
    port: uint = 9000
}

pub main() = {
    cfg := ServerConfig { port: 3000 }
    log("host={cfg.host} port={cfg.port}")
}
Enum + matchexamples/enums
type Color =
    | Red
    | Custom(int, int, int)

describe(c) = match c {
    Color.Red -> "red"
    Color.Custom(r, g, b) -> "rgb({r},{g},{b})"
}
Function valuesexamples/closures
apply(f, x) = f(x)
double(n) = n * 2

pub main() = {
    inc := |x| x + 1
    print(apply(double, 21))
    print(apply(_ * 2, 21))
    print(inc(41))
}
Implicit closuresexamples/closures
apply(f, x) = f(x)
run(f) = f(21)
label(g, p) = g(p)

type Person = { name: str }
type Vec2 = {
    x: float
    y: float
}
impl Vec2 = {
    new(x, y) = Vec2 {
        x: x
        y: y
    }
    magnitude(self) = (self.x ** 2.0 + self.y ** 2.0) ** 0.5
}

pub main() = {
    print(run { |x| x * 2 })
    print(label(.name, Person { name: "Ada" }))
    print(apply(.magnitude(), Vec2.new(3.0, 4.0)))
}
Trait + implexamples/show_trait
trait Show = { show(self) -> str }

impl Show for Point = {
    show(self) = "({self.x},{self.y})"
}

label(x: T) = x.show()
Data shapeexamples/shapes
shape HasPosition = {
    x: float
    y: float
}

distance(a: HasPosition, b: HasPosition) -> float = {
    dx := a.x - b.x
    dy := a.y - b.y
    dx * dx + dy * dy
}
Genericsexamples/generics_implicit
type Pair = { left: A, right: B }

id(x: T) = x
first(p: Pair<A, B>) = p.left

trait Wrapper = { unwrap(self) -> T }
impl Wrapper for IntBox = {
    unwrap(self) = self.value
}
Parametric shapeexamples/shapes_generic
shape HasPosition = { x: T, y: T }

distance(a: HasPosition<T>, b: HasPosition<T>) = {
    dx := a.x - b.x
    dy := a.y - b.y
    dx * dx + dy * dy
}
Loopsexamples/loops
sum_vec(xs) = {
    total mut:= 0
    for x in xs {
        total = total + x
    }
    total
}

n mut:= 5
loop {
    if n == 0 then break n
    n = n - 1
}
Rust importexamples/rust_import
use serde_json { from_str, to_string }

pub main() = {
    v := from_str("[1, true]")
    print(to_string(v))
}
Teststest
test "greet works" = {
    assert_eq(greet("world"), "hello world")
}

test_compile_fail "unknown" = {
    definitely_not_a_builtin()
}
Async mainexamples/async_hello
pub main() = async {
    sleep_ms(1)
    print("async-ok")
}

Draft spec on GitHub → Tutorial →