Hacker News .hnnew | past | comments | ask | show | jobs | submitlogin

"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?



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


Cool, thanks for explaining. :) Would it be a compile-time or runtime error?


It would be a compile-time error saying (in essence) "multiple applicable methods in scope" and giving you a list of the available methods.


Awesome!




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

Search: