[swift-evolution] [Discussion] What is the future of tuples in Swift?

Adrian Zubarev adrian.zubarev at devandartist.com
Fri Mar 3 06:57:45 CST 2017

The question here is, how is a tuple different from a mathematical vector? I wasn’t referring to vector concepts from other languages, but used the keyword vector to indicate a shortcut that provides a fixed or an arbitrary length such as …T would do in variadic generics context.

A shortcut for (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) is probably not that bad to have. In my sketch it would be (vector(16) Int), but it still would be a tuple. Structs aren’t arrays, but we created a value type that represents dynamic arrays (called vectors in different languages) and called it Array. Furthermore the dynamic array is not a simple primitive type and contains a whole bunch of other things.

That said, I don’t see why tuples should not benefit from all of that, if features like parametrized extensions make it into Swift one day.

extension<…T> (T…) : MutableCollection { … }

// or from my sketch  
extension<vector generic T> (vector T) : MutableCollection { … }
Being able to tell the size of such a vector is more beneficial than only having the … pre- and postfix for arbitrary length.

Currently variadics return Array<T>, which is *kinda* fine, but is not fully correct, because the returned sequence cannot be empty.

Adrian Zubarev
Sent with Airmail

Am 3. März 2017 um 13:35:47, Tino Heth (2th at gmx.de) schrieb:

I think that tuples should remain what they are now. Static-length vectors should be types on their own and interact with tuples, with structs and with Array<…> in the same way.

I strongly agree: Fixed-size vectors are a well known and simple concept that shouldn't be conflated with tuples.

Afair there was a time when Swift had no set-type, and I think we are lucky that it was added, instead of forcing us to use other collections instead.
Mixing array and tuple feels like having a switch for array to behave like a set...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170303/8a3411d8/attachment-0001.html>

More information about the swift-evolution mailing list