Skip to main content

Types

Overview

Swirl is statically and strongly-typed. Its first-class types are:

Integral Types

IDSize (in bytes)Description
i818-bit signed integer
u818-bit unsigned integer
i16216-bit signed integer
u16216-bit unsigned integer
i32432-bit signed integer
u32432-bit unsigned integer
i64864-bit signed integer
u64864-bit unsigned integer
i12816128-bit signed integer
u12816128-bit unsigned integer

Floating Point (FP) Types

IDSize (in bytes)Description
f32432-bit FP type.
f64864-bit FP type.

Array Type

Swirl provides the following syntax to create an in-place array for a type:

// `T` is the type and `N` is the number of elements.
let arr: [T | N] = [x, y, z, ...];

You do not need to declare the type explicitly if you provide an initializer, the compiler can infer the array-type:

let arr = [1, 2, 3, 4];  // automatically inferred to [i32 | 4]

Slice Type

Slices provide a "view" for a sequence of elements, internally, a slice is akin to a struct containing a pointer (to the first element) and a size. They are syntactically represented as: &[T] (for immutable slices) or &mut [T] (for mutable slices).

Reference Type

A reference-object redirects operations performed on it to the object it's bound to. A reference cannot be reassigned once it has been created. A reference type is syntactically represented as &T (for immutable references) or &mut T (for mutable references).

Type Inference

The Swirl Compiler has a Type Deduction System, when no explicit-type declaration can be reached, inference is done based on the following axioms:

ValueAssume as type
String literalstr
Integer literali32
Float literalf64

Stay informed