3 ms·
> 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 interfa
by ackfoobar 4y ago
> 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.
- gridspy 4y agoRust'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).
- mk89 4y agoyou'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.