IMHO the following line of code contains a highly inconsistent syntax, because the rhs uses labels for some sort of assignment, where the lhs just marks a constant/variable after the colon.
let (x: x, y: y) = (x: 0, y: 0) // valid today -- Adrian Zubarev Sent with Airmail Am 5. Mai 2017 um 12:42:11, Adrian Zubarev (adrian.zuba...@devandartist.com) schrieb: Labels create more harm in tuple destructuring than they solve. let point = (x: 0, y: 0) let (myX, myY) = point // fine let (x: my_X, y: my_Y) = point // fine let tuple = (a: 0, innerTuple: point) let (myA, myInnerTuple) = tuple // The following destructuring can extract nested tuples as well let (a: a, innerTuple: (x: x, y: y)) = tuple // fine // Let's try the same without labels let (my_A, (myNewX, myNewY)) = tuple // error: cannot express tuple conversion '(a: Int, innerTuple: (x: Int, y: Int))' to '(Int, (Int, Int))' // Wait what? It did worked above with `point` // Let's try something else let (a: _, innerTuple: (newX, newY)) = tuple // '(a: Int, innerTuple: (x: Int, y: Int))' to '(a: Int, innerTuple: (Int, Int))' // Yet another approach let (a: _, innerTuple: inner) = tuple // fine >From this I conclude that tuple destructuring creates a new tuple, which is >not my intention at all, at least not in terms of extracting data. The types >become incompatible with each other if not labeled properly and that’s why we >cannot omit unwanted labels and are forced to either type them all out to >extract nested data or none of them at all. -- Adrian Zubarev Sent with Airmail Am 5. Mai 2017 um 09:32:02, Xiaodi Wu (xiaodi...@gmail.com) schrieb: On Fri, May 5, 2017 at 2:28 AM, Adrian Zubarev <adrian.zuba...@devandartist.com> wrote: I’m not arguing to remove all labels in Swift. Labels are great, this is a fact for sure. The point I was trying to make is that labels in tuples how either a meaning or not at all. // This is a shortcut for the tuple type `(x: Int, y: Int)` let foo = (x: 0, y: 0) // In this case the labels are only used for description, // they do not server any benefit here are most likely redundant let (x: x, y: y) = foo Labels elsewhere are a different story and I do support the cosmetic addition Chris Lattner sketched out here: https://lists.swift.org/pipermail/swift-evolution-announce/2016-July/000233.html However this is about closures and not tuples, I don’t think this would anyhow affect the removal of labels in tuple destructuring. Plus I don’t see this to create an inconsistent in Swift, because as I already said, labels in tuple destructuring are useless. How come? I just illustrated their use. They help humans write correct code by allowing the compiler to check an assertion that the human knows which labels go with which positions in the tuple.
_______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution