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

> I don't know Rust, but they remind me of Scala traits. I guess it's conceptually the same

Rust's traits are typeclasses. Scala's traits are like Java interfaces but more.



Rust's dynamic traits are like Java or C# Interfaces.

Rust's Static traits are used like C++ templates but with more compiler checks and guidance.

In both cases, you can separate the code that implements the trait from the class itself (like a partial class). In Rust you can also retroactively declare a trait and then implement that trait for a class you like (even someone else's class, or a standard class).


you're right, Scala has also type classes, though. Generics, traits, variance, etc., are all quite sophisticated in Scala. I wouldn't say it's taken from Rust. The idea had been there for a while.




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

Search: