2 ms·
Every language has its own design features that end up influencing its generics system. Java has subtyping (in the form of class inheritance). Rust has lifeti
by comex 4y ago
Every language has its own design features that end up influencing its generics system. Java has subtyping (in the form of class inheritance). Rust has lifetimes and linear types. Go has its ‘structurally typed’ interfaces (which are the reason impossible combinations of constraints exist in the first place).
Haskell has none of those, but it has plenty of other features that at least historically caused exponential compilation time [1] and unsoundness [2].
Even C++ arguably falls into that category to an extent. Its template system definitely could have been designed better, and using Haskell-like type signatures like Rust does is arguably a better approach… but Rust trait signatures tend to be more complex and less elegant than Haskell ones, because the simple and elegant ones have runtime overhead that Rust, like C++, isn’t willing to accept. (For example, see functions being a trait as opposed to a type.)
And even Rust struggles to match C++ in metaprogramming expressivity, which also helps C++ reduce runtime overhead. Upcoming Rust features like `const fn` and specialization will help with that, but both have been ‘upcoming’ for many years…
[1] https://news.ycombinator.com/item?id=8130487 https://news.ycombinator.com/item?id=8130487
[2] https://gitlab.haskell.org/ghc/ghc/-/issues/7148 https://gitlab.haskell.org/ghc/ghc/-/issues/7148