> On May 30, 2017, at 03:25, Pavol Vaskovic <[email protected]> wrote:
>
>> On Tue, May 30, 2017 at 7:51 AM, David Sweeris <[email protected]> wrote:
>>
>> `(Int, Int, Int, Int)` isn't *that* horrible compared to "[Int x 4]", but
>> would you want to replace "[Int8 x 10000]" with the multipage-long tuple
>> equivalent?
>
> 😳
> It would be really helpful to my understanding, if you spoke about a
> practical use case. This reads as a contrived counterexample to me…
>
> If your type really has 10 000 values in it, why does it have to be static,
> why doesn't normal Array fit the bill?
Sure, I meant it as an example of how unwieldy large tuples can be. Even medium
ones, really. Tuples are great for bundling a few values, but much more than
that any they become annoying to work with because there's no easy way to
iterate through them. As a more realistic example, what if you want a
stack-allocated 256-element buffer (which is a real possibility since
statically-allocated C arrays are imported as tuples)? You have to manually
keep track of i, because you have to hard-code which element you're addressing
("buf.0", "buf.1", etc), rather than being able to look it up directly from an
index variable like, well, an array ("buf[i]").
Plus the fact that they can't conform to protocols really limits their
usefulness in filling the role of a "normal" type. For instance, even though
you could easily create the normal, 64-bit hash value from an instance of a
`(Int32, Int32)` simply by concatenating the two elements' bits, you can't
create a `Dictionary<(Int32, Int32), SomeType>` because there's no mechanism to
get `(Int, Int)` to conform to Dictionary's `Hashable` requirement.
Could both of these features get added to Tuples? From a technically PoV, sure,
and it's been discussed in previous threads. IMHO we'd get more benefit out of
adding support for variadic generic parameters and using literal values as
generic parameters (both of which have also been previously discussed).
But it's all out of scope until after Swift 4 comes out, because none of this
affects ABI or source-code compatibility.
- Dave Sweeris_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution