<div dir="ltr">On Mon, May 8, 2017 at 1:30 AM, Adrian Zubarev via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div class="m_4676426306976903498bloop_markdown"><p>Exactly, everything else is simply an excuse and nothing more. Tuple destructuring is not even aligned to enum case patterns at all, because it only uses the shorthand version and does not allow us to write the full explicit version.</p>
<pre><code class="m_4676426306976903498swift">enum Foo { case a(b: Int, c: Int) }
switch Foo.a(b: 42, c: 0) {
case let .a(b: num1, c: num2): …</code></pre></div></div></blockquote><div><br></div><div>You've just demonstrated how enum case patterns align with tuple patterns. This is exactly the same syntax. Here, too, no type is allowed after the colon. In fact, during discussion about allowing cases with the same base name, it was shown that overloading cases would be tricky precisely because of this: you're not allowed to disambiguate by writing `case let .a(b: num1: Int, c: num2: Int)` if two cases differ only by the type of their arguments.</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div class="m_4676426306976903498bloop_markdown"><pre><code class="m_4676426306976903498swift">
// Or the explicit longer version:
case .a(b: let num1, c: let: num2): …
}
</code></pre>
<p>Tuple destructuring do not support the latter, which in our previous example would really be unambiguous.</p>
<pre><code class="m_4676426306976903498swift">let tuple: (x: Int, y: Int) = (3, 1)
// Short version:
let (x: Int, y: Double): (x: Int, y: Int) = tuple
// Not supported explicit version:
(x: let Int, y: let Double) = tuple
</code></pre>
<p>Why is that the case? Because tuple destructuring creates another tuple on the left side of the same tuple type as the tuple on the right side of the assignment operator.</p></div></div></blockquote><div><br></div><div>I see no reason why that syntax could not also be supported, other than that there's no demand for it.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div class="m_4676426306976903498bloop_markdown">
<p>Erica Sudan has a proposal, which could change that for guards and ifs (second design): <a href="https://github.com/erica/swift-evolution/blob/783fdf8d3723d51f350b917af23c207cebdd1ad7/proposals/9999-ifcaseguardcase.md" target="_blank">https://github.com/erica/<wbr>swift-evolution/blob/<wbr>783fdf8d3723d51f350b917af23c20<wbr>7cebdd1ad7/proposals/9999-<wbr>ifcaseguardcase.md</a></p>
<p></p></div><div class="m_4676426306976903498bloop_original_html"><span class=""><div id="m_4676426306976903498bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div> <br> <div id="m_4676426306976903498bloop_sign_1494224089726146048" class="m_4676426306976903498bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">-- <br>Adrian Zubarev<br>Sent with Airmail</div></div> <br></span><div><div class="h5"><p class="m_4676426306976903498airmail_on">Am 8. Mai 2017 um 07:16:50, David Hart via swift-evolution (<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>) schrieb:</p> <blockquote type="cite" class="m_4676426306976903498clean_bq"><span><div dir="auto"><div></div><div>
<div><br></div>
<div>On 7 May 2017, at 00:21, Xiaodi Wu via swift-evolution
<<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>
wrote:<br>
<br></div>
<blockquote type="cite">
<div>To which human would it be misleading?<br>
<br>
To the writer? No, because the compiler will warn you right away.
By the time you're done with writing the first line, it'll warn you
that Int and Double are unused variables. And if you try to use x
and y, you get an error.<br>
<br>
To the reader? Only if the writer knowingly wrote this misleading
code. In other words, it's a nice puzzle, but no reader will
encounter this in real-world code, unless they're being tormented
by the writer on purpose.<br></div>
</blockquote>
<div><br></div>
<div>IMHO, the fact that the compiler warns you does no change the
fact that it's a very confusing part of the language. It should not
be an excuse for fixing it. Consistency teaches us to expect a type
after a colon.</div>
<br>
<blockquote type="cite">
<div>
<div class="gmail_quote">
<div dir="ltr">On Sat, May 6, 2017 at 16:28 Brent Royal-Gordon
<<a href="mailto:brent@architechies.com" target="_blank">brent@architechies.com</a>>
wrote:<br></div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
> On May 5, 2017, at 11:06 PM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>> wrote:<br>
><br>
> The identifier after a colon is *never* a type in any pattern
matching, and there's no need of which I'm aware to support type
annotations in pattern matching. We put colons after labels, and
the current syntax is perfectly consistent here. What is the defect
you're trying to cure?<br>
<br>
The defect underlying this proposal: `let (x: Int, y: Double)`
looks like it's declaring `x` and `y` of types `Int` and `Double`,
but it's actually declaring `Int` and `Double` and binding them to
`x` and `y`. Your code's meaning is perfectly unambiguous to the
compiler, of course, but it's misleading to the human.<br>
<br>
--<br>
Brent Royal-Gordon<br>
Architechies<br>
<br></blockquote>
</div>
</div>
</blockquote>
<blockquote type="cite">
<div>
<span>______________________________<wbr>_________________</span><br>
<span>swift-evolution mailing list</span><br>
<span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br>
<span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a></span><br>
</div>
</blockquote>
______________________________<wbr>_________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br></div></div></span></blockquote></div></div></div><div class="m_4676426306976903498bloop_markdown"><p></p></div></div><br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div></div>