Luce
Luce BaseSourceLuciaOS

4. Types

4.1 Scalars#

TypeValues
intsigned 64-bit integers; arithmetic traps on overflow (§6.2)
floatIEEE binary64
booltrue, false
strimmutable UTF-8 text with value semantics
bytesimmutable byte sequence with value semantics
unitthe one value () of a function that returns nothing
neverthe 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#

SpellingMeaning
(A, B)tuple, a value
struct Namea named value with fields (§9.1)
enum Namea closed set of cases, each with an optional payload (§9.2)
class Namea 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) -> Ra function value, possibly a closure (§7.4)
interface Namea 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.