traits

Function traits 

Source
pub fn traits() -> Vec<TraitSig>
Expand description

The traits every program has.

One, and it is the one SICP §2.5.1 builds by hand: generic arithmetic. The book’s answer to “how do rationals join a tower that already has integers” is a set of generic operations — add, sub, mul, div — that each type installs an implementation for, and that is exactly a trait. docs/32 §32.3 resolved + from its operands and said an ad-hoc resolution was “the honest thing to build before traits exist”; they exist, so + resolves through this when its operands are neither Int nor Float nor Str.

The method names are the book’s. A tower is only worth having if a third floor can be added from outside the language, and impl Num for Rational is how §2.1.1’s exercise stops being about function names and starts being about data abstraction.

It is not published: own_traits is what a .becki carries, and this belongs to the language rather than to any module. Nor is it implemented for Int or Float — those go through the primitives, because a tower whose bottom floor is a dictionary call would make every existing program slower to prove a point.