2 ms·
> typeclass based generics (Rust, Haskell) have all those pros and none of the cons My understanding is that typeclasses incur a runtime penalty on invocations
by munificent 8y ago
> typeclass based generics (Rust, Haskell) have all those pros and none of the cons
My understanding is that typeclasses incur a runtime penalty on invocations since the typeclass essentially carries around its V-table with it at runtime.
> none of the gains you claim are inherently lost on Java-style generics either. It's just that Java has funny language limitations, that do not apply if you remove the incompatible requisites from the language.
I don't understand how the last sentence of that does not invalidate the first. If you remove those limitations, what you get is not Java and would lose many of the other benefits that being Java has.
- steveklabnik 8y agoIn Rust, type classes do not have to carrry that overhead; when you use them as a trait bound, you get monomirphized code. When you use them as a trait object, you do carry the vtable around. For other languages, you may be correct in all cases.
- kibwen 8y agoAnd it's worth mentioning that the "trait object" form of generics is relatively rare in Rust code; there's a fair amount of friction to using them that makes them somewhat of a beginner hurdle considering how easy they are to reach for (which the future `dyn` keyword intends to rectify).