• 0 Posts
  • 9 Comments
Joined 2 years ago
cake
Cake day: June 15th, 2023

help-circle


  • Depending on your language, your closest analogue is going to be interfaces. C# even has a where clause where you can restrict a generic type such that any type substituted must implements one or more interfaces. You can get quite a bit of trait like working there, from the function input side of stuff.

    The biggest problem is, you can’t implement an interface for a type unless you have access to the type. So you’d have to really on wrapping types you don’t own to apply trait like interfaces to it.

    And then there’s minor issues like, no such thing as associated types, or being able to specify constants in a definition. But you can usually work around that in a less nice way.