Pelago

Types

The built-in types and how types are written.

Numbers

TypeMeaning
int, uintThe default signed integer (64 bits) and the unsigned machine integer.
int8, int16, int32, int64Signed integers of a given width.
uint8, uint16, uint32, uint64Unsigned integers of a given width. byte is another name for uint8.
int128, uint128, int256, uint256Wide integers, with the same checked arithmetic. See Wide integers.
float, float32IEEE 754 floating point, 64 and 32 bits.
float16, float128, float256IEEE 754 formats implemented in software. See Wide and narrow floats.

Arithmetic on every integer type is checked: a result that does not fit stops the program. A narrower integer is made from an int explicitly with wrapToByte(), toByteChecked() and the matching methods for the other widths (wrapToInt16, toInt32Checked, ...). The first wraps around and the second returns an option.

Text and truth

TypeMeaning
booltrue or false.
charA single character.
stringOwned UTF-8 text.
strA view of text that belongs to something else, such as the pieces returned by split.

Compound types

TypeExampleMeaning
Tuple(int, string)A fixed group of values; fields are t.0, t.1.
Braid(int, string; 4)A fixed-size run whose types repeat in a cycle. See Braids.
List[int] or list<int>A growable sequence.
Mapmap<string, int>Keys with values.
Setset<int>Unique values.
Range0..10A span of integers.
Boxbox<tree>A value stored on the heap.

Options, results and functions

TypeMeaning
T?A T or none.
T ! EA T or an error E.
fn(A, B) -> RA function or closure. once fn marks a closure that may be called only once.
neverThe type of an expression that does not return, such as panic("...").

A function without a result type returns nothing.

Types you define

struct, enum, obj and interface declare new types; see the guide. A value of type any shape holds any type that implements the interface shape. Generic types and functions take type parameters in angle brackets, optionally bounded: fn largest<T: order>(a: T, b: T) -> T.

Standard interfaces include order (comparison with <), eq, show (conversion to text), and the operator interfaces add, sub, mul, div, rem and neg, which a type implements to support the matching operator.

Aliases

type meters = float

fn main() {
    const m: meters = 2.5
    print("#m")
}
2.5

An alias is another name for the same type, not a new type.

On this page