Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Types

Wax types map directly to WebAssembly types.

Value Types

WasmWaxNotes
i32i3232-bit integer
i64i6464-bit integer
f32f3232-bit float
f64f6464-bit float
v128v128128-bit vector
(ref null <ht>)&?<ht>Nullable reference to heap type <ht>
(ref <ht>)&<ht>Non-nullable reference to heap type <ht>

Storage Types

Storage types are used in fields of structs and arrays to define packed data.

WasmWaxNotes
i8i88-bit integer (packed)
i16i1616-bit integer (packed)
valtypevaltypeAny value type

Heap Types

WasmWax
funcfunc
externextern
anyany
eqeq
structstruct
arrayarray
i31i31
exnexn
noexternnoextern
nofuncnofunc
noexnnoexn
nonenone
<typeidx><identifier>

Composite Types

Recursive Types

Wax allows defining recursive reference types using rec { ... }.

rec {
    type list = { head: i32, tail: node }
    type node = [list]
}

Structs

type point = { x: i32, y: i32 }
type mutable_point = { mut x: i32, mut y: i32 }

Maps to Wasm (type $point (struct (field i32) (field i32))).

Arrays

type bytes = [i8]
type mutable_bytes = [mut i8]

Maps to Wasm (type $bytes (array i8)).

Functions

type binop = fn(_: i32, _: i32) -> i32

Maps to Wasm (type $binop (func (param i32 i32) (result i32))).

Supertypes and Finality

Types are final by default. To make a type open (extensible), use the open keyword. To specify a supertype, use : supertype before the assignment.

type point = { x: i32, y: i32 }
type point3d : point = { z: i32 }        ;; extend point (if point was open)
type open_point = open { x: i32 }        ;; non-final type
type sub_point : open_point = { y: i32 } ;; ok