Types

Scalar types

CategoryTypes
Signed integersint, i8, i16, i32, i64, isize
Unsigned integersu8, u16, u32, u64, usize, uint8, uint16, uint32, uint64
Realsreal, real32, real64
Otherbool, glyph, text, unit

unit is the type of an expression with no meaningful value (for example a function that returns nothing).

Text and glyphs

A text is an immutable string; a glyph is a single character. Text supports indexing (returning a glyph), slicing, len, and the + operator:

import io;

name: text = "Ada";
greeting: text = "Hi, " + name + "!";   // text + text
shout: text = greeting + '!';           // a glyph appends a character
io.println(greeting);                    // Hi, Ada!
io.println("ab" + "cd" + "ef");          // abcdef

+ joins two text values, and a glyph on either side is appended as a single character (glyph + glyph remains a numeric error). The text module builds on it with helpers such as repeat, reverse, to_upper, to_lower, replace, split, pad_start, pad_end, and the free join function. To interpolate non-text values, use fmt.format.

Arrays

An array type is written [T]. Arrays support literals, indexing, slicing, len, push, and pop, plus a large set of stdlib helpers (see array).

import io;

values: [int] = [1, 2, 3, 4];
values.push(5);
io.println(values.len());     // 5
io.println(values[0]);        // 1
middle: [int] = values[1:3];

Slice bounds are zero-based and the right bound is excluded. Either bound may be omitted (values[:end], values[start:], or values[:]). Both bounds must be within 0..values.len() and the start cannot exceed the end.

Array assignment shares the same mutable array. Use import array; and values.copy() for a fresh outer array; that operation is shallow. See Values, copying, and mutation.

Tuples

Tuples group a fixed number of values of possibly different types and can be destructured on assignment.

pair = (1, "one");
(number, label) = pair;

The tuple shell is immutable. Arrays and records stored in tuple elements keep their normal shared-handle semantics.

Type aliases

Type aliases give a shorter name to an existing type. They are transparent compile-time aliases, not new runtime types, and can target primitive, array, tuple, record, choice, generic, and module-qualified types.

import matrix;
import outcome;

type Count = int;
type Counts = [Count];
type Vec = matrix.Vector<real64>;

type VecOf<T> = matrix.Vector<T>;
type Pair<T, U> = (T, U);
type TextOutcome<T> = outcome.Outcome<T, text>;

Generic aliases take one or more type arguments and substitute them transparently into their target. They may target other aliases and module-qualified types, and the number of arguments must match the declared parameters exactly. Alias parameters are unbounded in the current release; bounds and named const parameters are future extensions.

Explicit casts

Convert between numeric types with the to operator.

value = 17;
exact: real64 = value to real64;