[swift-evolution] [Proposal][Discussion] Deprecate Tuple Shuffles
André Videla
andre.videla at gmail.com
Mon May 8 03:35:16 CDT 2017
By the way, it seems that the only way to get rid of this clever puzzle is
to enforce uppercase for the first letter of type identifiers and lower
case for values identifiers.
2017-05-08 10:24 GMT+02:00 Adrian Zubarev via swift-evolution <
swift-evolution at swift.org>:
> I still have to disagree on that. Tuple patterns are not consistent in
> Swift.
>
> Here is a small proof of my claim:
>
> enum Foo {
>
> case a(b: Int)
> }
>
> switch Foo.a(b: 10) {
>
> case .a(b: let x):
> print(x)
> }
>
> let tuple = (x: 2, y: 20)
>
> switch tuple {
>
> case (x: let a, y: let b):
> print(a); print(b)
> }
>
> (x: let a, y: let b): (x: Int, y: Int) = tuple // Error!!!
>
> Tuple destructuring only works using the shorthand pattern, which _can_
> lead to all those puzzles from the discussion.
> ------------------------------
>
> The shorthand form ‘Is good and beautiful’ (German proverb), but it can do
> more harm than it should. Personally I would entirely ban the shorthand
> version unless we’ve got a superior version of it without all these issues.
> ------------------------------
>
> By the way not only tuples are affected by the mentioned puzzle:
>
> enum Foo {
>
> case sum(x: Int, y: Int)
> }
>
> switch Foo.sum(x: 3, y: 1) {
>
> case let .sum(x: Int, y: Double):
> print(Int + Double) // prints 4
> }
>
>
>
> --
> Adrian Zubarev
> Sent with Airmail
>
> Am 8. Mai 2017 um 09:28:52, Xiaodi Wu via swift-evolution (
> swift-evolution at swift.org) schrieb:
>
> But, in any case, with respect to consistency with the rest of the
> language, tuple patterns with labels are *supremely* consistent.
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170508/0cffe866/attachment.html>
More information about the swift-evolution
mailing list