<div dir="ltr">I just realized this message was not sent to evolution<div><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">André Videla</b> <span dir="ltr">&lt;<a href="mailto:andre.videla@gmail.com">andre.videla@gmail.com</a>&gt;</span><br>Date: 2017-05-08 9:51 GMT+02:00<br>Subject: Re: [swift-evolution] [Proposal][Discussion] Deprecate Tuple Shuffles<br>To: Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com">xiaodi.wu@gmail.com</a>&gt;<br><br><br><div dir="ltr"><div class="gmail_extra">Let me show you:</div><div class="gmail_extra">







<p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s1">assume we have this data type which is just a pair of Ints</span></p><span class=""><p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s1">enum</span><span class="m_-245275765906510998gmail-s2"> Pair {</span></p><p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s2">    </span><span class="m_-245275765906510998gmail-s1">case</span><span class="m_-245275765906510998gmail-s2"> point(x: </span><span class="m_-245275765906510998gmail-s3">Int</span><span class="m_-245275765906510998gmail-s2">, y: </span><span class="m_-245275765906510998gmail-s3">Int</span><span class="m_-245275765906510998gmail-s2">)</span></p><p class="m_-245275765906510998gmail-p1">









</p><p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s2">}</span></p></span><p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s2">and see how Swift allows us to deconstruct it:</span></p></div><div class="gmail_extra">







<p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s1">if</span><span class="m_-245275765906510998gmail-s2"> </span><span class="m_-245275765906510998gmail-s1">case</span><span class="m_-245275765906510998gmail-s2"> .</span><span class="m_-245275765906510998gmail-s3">point</span><span class="m_-245275765906510998gmail-s2">(let x, let y) = </span><span class="m_-245275765906510998gmail-s3">Pair</span><span class="m_-245275765906510998gmail-s2">.</span><span class="m_-245275765906510998gmail-s3">point</span><span class="m_-245275765906510998gmail-s2">(x: </span><span class="m_-245275765906510998gmail-s4">3</span><span class="m_-245275765906510998gmail-s2">, y: </span><span class="m_-245275765906510998gmail-s4">5</span><span class="m_-245275765906510998gmail-s2">) {</span></p>
<p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s2">    </span><span class="m_-245275765906510998gmail-s5">print</span><span class="m_-245275765906510998gmail-s2">(</span><span class="m_-245275765906510998gmail-s4">&quot;</span><span class="m_-245275765906510998gmail-s2">\</span><span class="m_-245275765906510998gmail-s4">(</span><span class="m_-245275765906510998gmail-s2">x</span><span class="m_-245275765906510998gmail-s4">), </span><span class="m_-245275765906510998gmail-s2">\</span><span class="m_-245275765906510998gmail-s4">(</span><span class="m_-245275765906510998gmail-s2">y</span><span class="m_-245275765906510998gmail-s4">)&quot;</span><span class="m_-245275765906510998gmail-s2">)</span></p>
<p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s2">}</span></p><p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s2">this is perfectly fine. Even if the labels are omitted the structure is kept and x = 3 and y = 5</span></p>
<p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s1">if</span><span class="m_-245275765906510998gmail-s2"> </span><span class="m_-245275765906510998gmail-s1">case</span><span class="m_-245275765906510998gmail-s2"> .</span><span class="m_-245275765906510998gmail-s3">point</span><span class="m_-245275765906510998gmail-s2">(x: </span><span class="m_-245275765906510998gmail-s1">let</span><span class="m_-245275765906510998gmail-s2"> x, y: </span><span class="m_-245275765906510998gmail-s1">let</span><span class="m_-245275765906510998gmail-s2"> y) = </span><span class="m_-245275765906510998gmail-s3">Pair</span><span class="m_-245275765906510998gmail-s2">.</span><span class="m_-245275765906510998gmail-s3">point</span><span class="m_-245275765906510998gmail-s2">(x: </span><span class="m_-245275765906510998gmail-s4">3</span><span class="m_-245275765906510998gmail-s2">, y: </span><span class="m_-245275765906510998gmail-s4">5</span><span class="m_-245275765906510998gmail-s2">) {</span></p>
<p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s2">    </span><span class="m_-245275765906510998gmail-s5">print</span><span class="m_-245275765906510998gmail-s2">(</span><span class="m_-245275765906510998gmail-s4">&quot;</span><span class="m_-245275765906510998gmail-s2">\</span><span class="m_-245275765906510998gmail-s4">(</span><span class="m_-245275765906510998gmail-s2">x</span><span class="m_-245275765906510998gmail-s4">), </span><span class="m_-245275765906510998gmail-s2">\</span><span class="m_-245275765906510998gmail-s4">(</span><span class="m_-245275765906510998gmail-s2">y</span><span class="m_-245275765906510998gmail-s4">)&quot;</span><span class="m_-245275765906510998gmail-s2">)</span></p>
<p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s2">}</span></p><p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s2">perfectly fine, x and y are given and correspond to the actual label of the enum case x = 3, y = 5</span></p>
<p class="m_-245275765906510998gmail-p2"><span class="m_-245275765906510998gmail-s2"></span><br></p>
<p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s1">if</span><span class="m_-245275765906510998gmail-s2"> </span><span class="m_-245275765906510998gmail-s1">case</span><span class="m_-245275765906510998gmail-s2"> .point(y: </span><span class="m_-245275765906510998gmail-s1">let</span><span class="m_-245275765906510998gmail-s2"> x, x: </span><span class="m_-245275765906510998gmail-s1">let</span><span class="m_-245275765906510998gmail-s2"> y) = </span><span class="m_-245275765906510998gmail-s3">Pair</span><span class="m_-245275765906510998gmail-s2">.</span><span class="m_-245275765906510998gmail-s3">point</span><span class="m_-245275765906510998gmail-s2">(x: </span><span class="m_-245275765906510998gmail-s4">3</span><span class="m_-245275765906510998gmail-s2">, y: </span><span class="m_-245275765906510998gmail-s4">5</span><span class="m_-245275765906510998gmail-s2">) {</span></p>
<p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s2">    print(</span><span class="m_-245275765906510998gmail-s4">&quot;</span><span class="m_-245275765906510998gmail-s2">\</span><span class="m_-245275765906510998gmail-s4">(</span><span class="m_-245275765906510998gmail-s2">x</span><span class="m_-245275765906510998gmail-s4">), </span><span class="m_-245275765906510998gmail-s2">\</span><span class="m_-245275765906510998gmail-s4">(</span><span class="m_-245275765906510998gmail-s2">y</span><span class="m_-245275765906510998gmail-s4">)&quot;</span><span class="m_-245275765906510998gmail-s2">)</span></p>
<p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s2">}</span></p><p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s2">This is an error, as expected, labels do not correspond to any existing known structure and the match makes no sense. It does not compile</span></p>
<p class="m_-245275765906510998gmail-p1">Now we refactor the code a bit and we start using a pair instead of an enum  case</p><p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s1">if</span><span class="m_-245275765906510998gmail-s2"> </span><span class="m_-245275765906510998gmail-s1">case</span><span class="m_-245275765906510998gmail-s2"> (let x, let y) = (x: </span><span class="m_-245275765906510998gmail-s4">3</span><span class="m_-245275765906510998gmail-s2">, y: </span><span class="m_-245275765906510998gmail-s4">5</span><span class="m_-245275765906510998gmail-s2">) {</span></p>
<p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s2">    </span><span class="m_-245275765906510998gmail-s5">print</span><span class="m_-245275765906510998gmail-s2">(</span><span class="m_-245275765906510998gmail-s4">&quot;</span><span class="m_-245275765906510998gmail-s2">\</span><span class="m_-245275765906510998gmail-s4">(</span><span class="m_-245275765906510998gmail-s2">x</span><span class="m_-245275765906510998gmail-s4">), </span><span class="m_-245275765906510998gmail-s2">\</span><span class="m_-245275765906510998gmail-s4">(</span><span class="m_-245275765906510998gmail-s2">y</span><span class="m_-245275765906510998gmail-s4">)&quot;</span><span class="m_-245275765906510998gmail-s2">)</span></p>
<p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s2">}</span></p><p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s2">this is fine since the structure is preserved from the value on the right, x = 3, y = 5</span></p>
<p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s1">if</span><span class="m_-245275765906510998gmail-s2"> </span><span class="m_-245275765906510998gmail-s1">case</span><span class="m_-245275765906510998gmail-s2"> (x: </span><span class="m_-245275765906510998gmail-s1">let</span><span class="m_-245275765906510998gmail-s2"> x, y: </span><span class="m_-245275765906510998gmail-s1">let</span><span class="m_-245275765906510998gmail-s2"> y) = (x: </span><span class="m_-245275765906510998gmail-s4">3</span><span class="m_-245275765906510998gmail-s2">, y: </span><span class="m_-245275765906510998gmail-s4">5</span><span class="m_-245275765906510998gmail-s2">) {</span></p>
<p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s2">    </span><span class="m_-245275765906510998gmail-s5">print</span><span class="m_-245275765906510998gmail-s2">(</span><span class="m_-245275765906510998gmail-s4">&quot;</span><span class="m_-245275765906510998gmail-s2">\</span><span class="m_-245275765906510998gmail-s4">(</span><span class="m_-245275765906510998gmail-s2">x</span><span class="m_-245275765906510998gmail-s4">), </span><span class="m_-245275765906510998gmail-s2">\</span><span class="m_-245275765906510998gmail-s4">(</span><span class="m_-245275765906510998gmail-s2">y</span><span class="m_-245275765906510998gmail-s4">)&quot;</span><span class="m_-245275765906510998gmail-s2">)</span></p>
<p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s2">}</span></p><p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s2">this is fine since the labels correspond to the existing structure on the right x = 3, y = 5</span></p>
<p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s1">if</span><span class="m_-245275765906510998gmail-s2"> </span><span class="m_-245275765906510998gmail-s1">case</span><span class="m_-245275765906510998gmail-s2"> (y: </span><span class="m_-245275765906510998gmail-s1">let</span><span class="m_-245275765906510998gmail-s2"> x, x: </span><span class="m_-245275765906510998gmail-s1">let</span><span class="m_-245275765906510998gmail-s2"> y) = (x: </span><span class="m_-245275765906510998gmail-s4">3</span><span class="m_-245275765906510998gmail-s2">, y: </span><span class="m_-245275765906510998gmail-s4">5</span><span class="m_-245275765906510998gmail-s2">) {</span></p>
<p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s2">    </span><span class="m_-245275765906510998gmail-s5">print</span><span class="m_-245275765906510998gmail-s2">(</span><span class="m_-245275765906510998gmail-s4">&quot;</span><span class="m_-245275765906510998gmail-s2">\</span><span class="m_-245275765906510998gmail-s4">(</span><span class="m_-245275765906510998gmail-s2">x</span><span class="m_-245275765906510998gmail-s4">), </span><span class="m_-245275765906510998gmail-s2">\</span><span class="m_-245275765906510998gmail-s4">(</span><span class="m_-245275765906510998gmail-s2">y</span><span class="m_-245275765906510998gmail-s4">)&quot;</span><span class="m_-245275765906510998gmail-s2">)</span></p>
<p class="m_-245275765906510998gmail-p1"><span class="m_-245275765906510998gmail-s2">}</span></p><p class="m_-245275765906510998gmail-p1">And this.</p><p class="m_-245275765906510998gmail-p1">This compiles even though the <b>structure matched does not correspond to the structure of the value against which it matches</b>.  x = 5, y = 3</p></div></div>
</div><br></div></div>