Language tour

A quick tour of insty — modules, functions, types, control flow, and the building blocks.

A whirlwind tour. Each section links to a deeper page where one exists.

Modules and imports

Every file starts with a module declaration. Imports use :: as the scope/directory separator, so a dependency @owner/package is imported as import owner::package.

module main

import std::io
import owner::package as pkg

Functions and variables

Functions use fun name(args) -> type. Variables require explicit types.

fun add(i32 a, i32 b) -> i32 {
    i32 total = a + b
    return total
}

Primitive types

  • Integers: i8, i16, i32, i64, i128, u8, u16, u32, u64, u128
  • Floats: f16, f32, f64, f128
  • Other: bool, text, void

Pointers use T*, address-of uses &x, dereference uses ~ptr. == / != on text compare content (null-safe); other pointer types compare by address.

Control flow

if, while, for, loop, switch, match, break, skip, and return.

fun sum(i32[] xs) -> i32 {
    i32 total = 0
    for x in xs {
        total = total + x
    }
    return total
}

Structs, classes, enums

struct Point {
    i32 x,
    i32 y
}

class Counter {
    i32 value

    constructor(i32 initial) {
        this.value = initial
    }

    fun inc() -> void {
        this.value = this.value + 1
    }
}

enum Status : i32 {
    Pending,
    Ready
}

Classes support constructors/destructors, methods, this, operator overloading, and RAII.

String interpolation

fun greet(text name) -> void {
    @println("Hello, $name!")
    @println("Sum is ${1 + 2}")
}

Builtins

Common builtins are prefixed with @: @sizeof, @malloc / @free / @realloc, @memcpy / @memset, @print / @println, @panic, @hash, and (in hosted mode) @syscall.

Going deeper