pub interface Ordered {
operator compare(self: Self, other: Self) -> Ordering
}
Standard interfaces for bounded generic functions. A type satisfies an interface by defining the operator method or the method it names — a built-in type by the stdlib's own, a program's type by its own (formal/operators.md). Types that support the < comparison operator. Satisfied by integer, single, float, text, and any type defining operator compare.
boolean is NOT among them, deliberately: it satisfies Equatable below and has no ordering, so false < true is a refusal rather than a convention the language picks for you. A program that wants it says so — (a as integer) < (b as integer). The same line bounds how null is ordered: that applies to the ordered types only, and a boolean null still compares with == like every other scalar.
ONE method is all a type has to define: inside a generic bounded by this, <, <=, > and >= all read it, each evaluating its operands exactly once.
pub interface Equatable {
}
Types that support the == equality operator: every type, compared by content at every depth (@C91). == is always structural and no type redefines it, so this declares nothing; a deep comparison of a type's own is a named method. A tuple compares element by element, as its concrete == does.
!= derives from it (a != b is !(a == b)).
pub interface Addable {
operator plus(self: Self, other: Self) -> Self
}
Types that support the + addition operator, returning the same type. Satisfied by integer, single, float, and any type defining operator plus.
pub interface Numeric {
operator times(self: Self, other: Self) -> Self
operator negate(self: Self) -> Self
}
Types that support * and - (unary negation). Separate from Addable so a generic can ask for the fewest operators it needs. Satisfied by integer, single, float, and any type defining operator times and operator negate.
Binary subtraction is Subtractable below and deliberately NOT here. One interface CAN declare both arities of -, but adding a requirement to Numeric would take satisfaction away from every type that meets it, which a compatible release may not do.
pub interface Subtractable {
operator minus(self: Self, other: Self) -> Self
}
Types that support binary - (subtraction), returning the same type. Satisfied by integer, single, float, and any type defining operator minus.
A bound of its own rather than a third requirement on Numeric, so <T: Numeric + Subtractable> gets negation and subtraction together from two interfaces. The built-in number types satisfy both.
pub interface Scalable {
fn scale(self: Self, factor: integer) -> integer
}
Types that support integer scaling via a scale method. Uses a method (not operator times): inside a <T: Numeric + …> body, * already means Numeric's Self * Self, so x * 2 there is refused ("operator '*' requires a concrete type") even when another bound declares operator times(self: Self, f: integer). Two SEPARATE generics may each bound their own T by an interface declaring the same method differently — a header binds its own type variable. User types satisfy Scalable by defining fn scale(self: T, factor: integer) -> integer.