Skip to content

Types and Inheritance

User-defined types are declared with type ... struct.

type Counter struct {
value i32
fn reset() {
this.value = 0
}
}

type ... struct is currently class-backed syntax in the runtime. Treat it as the user-facing way to define object-shaped types today, not as a value-type system.

Fields live directly in the type body. Methods use the same fn syntax as top-level functions.

type Box struct {
value i32
fn get() i32 {
return this.value
}
fn set(v i32) i32 {
this.value = v
return this.value
}
}

Use this inside methods to read or write the receiver.

Construction uses normal call syntax on the type name:

var counter = Counter()
var box Box = Box()

The language also supports aliases:

type Score i32

Aliases are part of the documented language surface in the README even though most examples in the repo focus on structs.

Single inheritance is available with < Parent.

type A struct {
fn greet() str {
return "A"
}
}
type B struct < A {
fn greet() str {
return super.greet() + "B"
}
}

Use super.method() to call an inherited implementation.

The compiler also supports operator annotations on methods. This is currently a real feature, but it is still narrower than a full custom-operator system.

Supported annotations today are limited to:

  • +
  • -
  • *
  • /
  • ==
  • !=
  • <
  • <=
  • >
  • >=