Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This matches my experience: ontological inheritance gets in the way. What we actually want is traits. What can something do, not what it is.


This seems like structural subtyping? Are these synonyms?


I 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.


More 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.


The only sub typing in Rust is lifetimes; other types have no sub typing.

Traits are “ad hoc polymorphism”.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: