4 ms·
"new traits can be implemented for existing types (as with Hash above). That means abstractions can be created after-the-fact, and applied to existing libraries
by nathan_long 11y ago
"new traits can be implemented for existing types (as with Hash above). That means abstractions can be created after-the-fact, and applied to existing libraries."
Sounds a bit like a Ruby monkey patch. What happens in case of conflict - my trait adds a .hash method, but there already was one?
- phaylon 11y agoTrait methods are only visible when the trait is in scope. So a conflict would only appear when both traits are imported and the method is called, in which case you'll have to disambiguate.
- nathan_long 11y agoCool, thanks for explaining. :) Would it be a compile-time or runtime error?
- phaylon 11y agoIt would be a compile-time error saying (in essence) "multiple applicable methods in scope" and giving you a list of the available methods.
- nathan_long 11y agoAwesome!