4. Types
4.1 Scalars#
| Type | Values |
|---|---|
int | signed 64-bit integers; arithmetic traps on overflow (§6.2) |
float | IEEE binary64 |
bool | true, false |
str | immutable UTF-8 text with value semantics |
bytes | immutable byte sequence with value semantics |
unit | the one value () of a function that returns nothing |
never | the type of an expression that does not produce a value: return, trap, error |
There is no implicit conversion between any two of these. int(x), float(x), str(x) and bool(x) convert explicitly (§6.5).
4.2 Composite types#
| Spelling | Meaning |
|---|---|
(A, B) | tuple, a value |
struct Name | a named value with fields (§9.1) |
enum Name | a closed set of cases, each with an optional payload (§9.2) |
class Name | a shared object with identity (§10) |
list[T], map[K, V], set[T] | mutable collections with identity (§11) |
T? | T or none (§12.1) |
T! | T or an Error (§12.2) |
func(A, B) -> R | a function value, possibly a closure (§7.4) |
interface Name | a capability a type declares it has (§13) |
task[T] | a running worker's future result (§14) |
Weak[T] | a non-owning reference to a class instance (§10.4) |
A type name is resolved in the module's scope. type Name = Type declares an alias, which is the same type. Every type has a spelling luce explain can print.
4.3 Inference#
Inference is local. A binding takes its type from its initialiser; a call's type arguments come from its arguments; a literal takes its type from the context it sits in, and defaults to int, float, str, list[T] of its elements. Signatures are always written: a function's parameters and result never infer from the body. T? and T! are written where they are meant and never inferred from a none or an error.
4.4 Equality, ordering and hashing#
Every value type has == and != by structure: scalars, str, bytes, tuples, structs whose fields have it, enums whose payloads have it, optionals of it, and collections of it. <, <=, >, >= are defined for int, float, str (scalar-value order, not locale), bytes, and tuples of those, and for a struct that declares Ordered (§13.3). hash is defined for every equatable value, consistently with ==, and is the same number in every execution (docs/RUNTIME.md states the function). Classes have identity, not equality: is and is not compare identity, and == on a class is an error unless it declares Equatable (§13.3).
4.5 Recursion#
A struct or enum may not contain itself by value. A class may refer to itself through any field, and a struct or enum may contain a class or a collection of itself.