3 ms·
This matches my experience: ontological inheritance gets in the way. What we actually want is traits. What can something do, not what it is.
by kaoD 9y ago
This matches my experience: ontological inheritance gets in the way. What we actually want is traits. What can something do, not what it is.
- weberc2 9y agoThis seems like structural subtyping? Are these synonyms?
- kaoD 9y agoI think traits (as I know them) are still nominal subtyping. E.g.: a Rust struct implementing a next() method does not implement the Iterator trait even if they are structurally equivalent. You have to explicitly implement the trait.
- steveklabnik 9y agoThe only sub typing in Rust is lifetimes; other types have no sub typing. Traits are “ad hoc polymorphism”.
- kazagistar 9y agoMore like interfaces. A lot of OOP languages just did it in a limited way where interfaces for a class are closed. Meanwhile in Haskell or Rust, you can define your interfaces, and then provide implementations of it for existing objects like String. Or the Scale workaround, which basically is implicitly converting to wrapper classes that implement the interface. With the goal being extending existing types with new shared behavior, without the limitations of full inheritence.