by whyever · 9y ago · 0 comments
It is unlikely you will ever see non-zero cost abstractions in idiomatic Rust.
That said, at some point, we'll be getting ATC, which is equivalent to HKT in many cases, but feels more Rusty.
- HKT: Higher-Kinded Types
- ATC: Alternative Type Constructors
From what I remember from the theory, higher-kinded types lead to a genuinely more difficult type inference problem (going from easy first-order unification to undecidable higher-order unification), while associated types are simply existential types (and in particular no more difficult than higher-rank polymorphism).
Re "extra", I'm not sure what you mean - does it mean that the abstraction is implemented efficiently, but still has the cost that is usually associated with that abstraction? For example, dynamic dispatch is as fast as a DIY dynamic dispatch in assembly?
The borrow checker, AFAIU, has a cost in that it forbids some (more efficient) shared data accesses that it can't prove safe but still are.
Yes, zero cost means you could not implement it in a more efficient way by hand.
> The borrow checker, AFAIU, has a cost in that it forbids some (more efficient) shared data accesses that it can't prove safe but still are.
This is not what it meant with "cost" in this context. It is zero cost because it only runs at compile time. That it rejects some valid programs is irrelevant, because it is zero cost for the programs it accepts.