ops
stdlib/core/ops.hk: the operator traits, Add and Sub.
a + b and a - b on non-numeric operands dispatch through these, the same way < routes through Ord.cmp and == through Eq.eq? (HANKI.md §3, §10). The numeric tower never reaches them: numeric operands keep their width-exact opcodes, and an operator impl whose Self is a builtin primitive is rejected outright. + on primitives has a single built-in meaning, and string concatenation remains explicit (.concat).
Both traits take a right-hand-side type parameter defaulting to Self (impl Add<Period> is homogeneous; impl Add<Instant, Duration> is heterogeneous) and bind an associated Output, the checked type of the whole a + b expression. The methods are pure defs, and an impl may not widen a trait method's effect row, and an operator can never perform effects. The operator family grows here (Mul/Div/Neg are recorded future scope), one module for all of it.
Add
trait Add<Rhs = Self>
Output
type Output
add
def add(self, rhs: Rhs) -> Output
The value of self + rhs. Implement this and + follows: the operator is the method, spelled infix.
@no-doctest: core has no Add impl (the flagship impls are in the extra-tier datetime module, whose operator section has the worked examples); the trait itself has nothing runnable to demo.
Sub
trait Sub<Rhs = Self>
Output
type Output
sub
def sub(self, rhs: Rhs) -> Output
The value of self - rhs.
@no-doctest: core has no Sub impl (the flagship impls are in the extra-tier datetime module, whose operator section has the worked examples); the trait itself has nothing runnable to demo.