5 ms·
It’s a historical limitation, with the power of lifting it only very recently stabilised (in the last couple of releases). Most things that were limited to 32 w
by chrismorgan 5y ago
It’s a historical limitation, with the power of lifting it only very recently stabilised (in the last couple of releases). Most things that were limited to 32 when this article was written aren’t any more, though the Default trait implementation still is.
The key term to search for and read up on is const generics.
This style of limitation is still present on tuples, which have implementations for common traits for up to 12-tuples. (See the bunch of implementations around https://doc.rust-lang.org/std/cmp/trait.PartialEq.html#impl-PartialEq%3C(A%2C%20B%2C%20C%2C%20D%2C%20E%2C%20F%2C%20G%2C%20H%2C%20I%2C%20J%2C%20K%2C%20L)%3E https://doc.rust-lang.org/std/cmp/trait.PartialEq.html#impl-... as an example, comparing it with the single “PartialEq<[B; N]> for [A; N]” implementation for all arrays!) This limitation will probably be sorted out eventually, but it takes time to settle on a design that satisfies everyone and is implementable.
- masklinn 5y ago> This limitation will probably be sorted out eventually, but it takes time to settle on a design that satisfies everyone and is implementable. That sounds unlikely, it’s would require not just const generics but some sort of variable arity generics. If Haskell doesn’t have it, I don’t really see Rust getting it.
- swsieber 5y agoThere have been various variable arity generic discussions on the internals forum (internals.rust-lang.org), but I think it's a significantly lower priority issue than the other stuff in flight. I think we might get it in a few years.
- chrismorgan 5y agoThis is my position, too. I think everyone agrees that we want to get generic tuples, but there are other higher priority issues still, so it’s mostly more a backburner project worth thinking about when designing things, and slowly working towards as good a design as we can come up with which fits in with the rest of the language (including future possibilities) as well as possible. Even in a vacuum it’s not trivial to design something both satisfactory and implementable, and when you add other language features, corners the language has been designed into, and corners you want to avoid painting the language into, it gets much harder still.
- Diggsey 5y agoWhy not? Rust isn't limited to what Haskell does, and a lot of it's features are driven by a desire for parity with C++, which does have variadic generics. Other languages in the same domain (like D) also have variadic generics.
- masklinn 5y agoBecause Rust’s generics are patterned after Haskell’s (traits are dual to type classes), not C++’ templates.
- Diggsey 5y agoYou're conflating traits with generics. Generics exist without traits, and in Rust they are more closely aligned with C++ templates than anything else, since they are implemented via monomorphisation, whereas in Haskell they are not. Regardless, Rust is not "patterned" after a single other language. It's influenced by many langauges, so it makes no sense to say that one feature is just copied straight from a specific other language.
- deleted 5y ago[deleted]