Introduce traits #40
KnightBreaker
started this conversation in
Ideas
Replies: 1 comment
-
|
This is on our roadmap, but a bit further down the road. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Every type should be able to conform to a trait, an interface/protocol like structure, not just classes that can conform to interfaces.
This is a much more powerful feature as together with retroactive extensions it would allow extending structs, enums, upcoming unions with additional shareable functionality.
Interfaces could just become a constrained subset of traits.
e.g. in Swift a
protocol P: AnyObjectis constrained to classes only, so it‘s like an interface, but aprotocol Q {}can be used by other types as well.This is important to replace stuff like how ToString currently works. We may want to take a value that generically can be converted to a string but with the current system and ToString being hoisted functions it's not possible.
Beta Was this translation helpful? Give feedback.
All reactions