<div dir="ltr">A related anecdote, a colleague and I found a bug yesterday in our project. We only realised because the compiler had an error because the tuple labels didn't match. The error message was not useful, but we would not have noticed the bug without the compiler error.<div><br></div><div>I'd support a proposal for a better error message :)<div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">let</span> rgb = (<span style="color:rgb(49,89,93)">hsbToHsl</span> <span style="color:rgb(49,89,93)">•</span> <span style="color:rgb(49,89,93)">hslToRgb</span>)(<span style="color:rgb(79,129,135)">h</span>, <span style="color:rgb(79,129,135)">s</span>, <span style="color:rgb(79,129,135)">b</span>)<br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><b>error: cannot invoke '•' with an argument list of type '(Float, Float, Float)'</b></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><b>let rgb = (hsbToHsl • hslToRgb)(h, s, b)</b></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><b><br></b></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><b>note: expected an argument list of type '(T)'</b></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><b>let rgb = (hsbToHsl • hslToRgb)(h, s, b)</b></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)">// it should have been this:</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)"><span style="color:rgb(187,44,162)">let</span><span style="color:rgb(0,0,0)"> rgb = (</span>hslToRgb<span style="color:rgb(0,0,0)"> </span>•<span style="color:rgb(0,0,0)"> </span>hsbToHsl<span style="color:rgb(0,0,0)">)(</span><span style="color:rgb(79,129,135)">h</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(79,129,135)">s</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(79,129,135)">b</span><span style="color:rgb(0,0,0)">)</span></p><div><br></div></div><div><span style="color:rgb(0,132,0);font-family:Menlo;font-size:11px">// The type signatures:</span></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">func</span> hslToRgb(hsl: (h: <span style="color:rgb(112,61,170)">Float</span>, s: <span style="color:rgb(112,61,170)">Float</span>, l: <span style="color:rgb(112,61,170)">Float</span>))</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> -> (r: <span style="color:rgb(112,61,170)">Float</span>, g: <span style="color:rgb(112,61,170)">Float</span>, b: <span style="color:rgb(112,61,170)">Float</span>)</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">func</span> hsbToHsl(hsb: (h: <span style="color:rgb(112,61,170)">Float</span>, s: <span style="color:rgb(112,61,170)">Float</span>, b: <span style="color:rgb(112,61,170)">Float</span>))</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> -> (h: <span style="color:rgb(112,61,170)">Float</span>, s: <span style="color:rgb(112,61,170)">Float</span>, l: <span style="color:rgb(112,61,170)">Float</span>)</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)">infix<span style="color:rgb(0,0,0)"> </span>operator<span style="color:rgb(0,0,0)"> • {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"> associativity<span style="color:rgb(0,0,0)"> left</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"> precedence<span style="color:rgb(0,0,0)"> </span><span style="color:rgb(39,42,216)">100</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">public</span> <span style="color:rgb(187,44,162)">func</span> •<T, U, V>(g: <span style="color:rgb(112,61,170)">U</span> -> <span style="color:rgb(112,61,170)">V</span>, f: <span style="color:rgb(112,61,170)">T</span> -> <span style="color:rgb(112,61,170)">U</span>) -> (<span style="color:rgb(112,61,170)">T</span> -> <span style="color:rgb(112,61,170)">V</span>)</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></p>As an aside: we removed the composite operator in the end because it greatly reduced performance, we tried to force inlining, it didn't make a difference. I haven't been able to work out a good reason why, hopefully someone here knows, otherwise I'll have to look at the compiler output.<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></p></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Feb 6, 2016 at 5:38 AM, David Hart via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">All of this discussion has given me food for thought and I’m not so sure it’s a proposal I’d still like to pursue.<div><div class="h5"><div><br></div><div><div><div><blockquote type="cite"><div>On 05 Feb 2016, at 16:20, Craig Cruden via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><div style="word-wrap:break-word"><blockquote type="cite"><div style="word-wrap:break-word">At a high level, I would think that a tuple would just be considered a “typed” heterogeneous list of values - that you should be able to access the same way that you access any list - same functions (map, reduce, etc.). <div><br></div><div>I guess you could view the “labels” as a quasi-column header of some sort, which means although you might not be able to “convert” from (a: Int, b: Int) to (x: Int, y: Int) …. you would be able to `map` the values and the "column headers” to (x: Int, y: Int).</div><div><br></div></div></blockquote><div><br></div>Shameless plug: which of course would make the concept of `cases` within the mapping of values within the tuple (heterogeneous list) very useful :p<br><div><br></div><div><br></div><div><br><blockquote type="cite"><div>On 2016-02-05, at 22:17:55, Craig Cruden <<a href="mailto:ccruden@novafore.com" target="_blank">ccruden@novafore.com</a>> wrote:</div><br><div><div style="word-wrap:break-word">At a high level, I would think that a tuple would just be considered a “typed” heterogeneous list of values - that you should be able to access the same way that you access any list - same functions (map, reduce, etc.). <div><br></div><div>I guess you could view the “labels” as a quasi-column header of some sort, which means although you might not be able to “convert” from (a: Int, b: Int) to (x: Int, y: Int) …. you would be able to `map` the values and the "column headers” to (x: Int, y: Int).</div><div><br></div><div><br></div><div><br><div><div><blockquote type="cite"><div>On 2016-02-05, at 19:41:19, Maximilian Hünenberger via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><div dir="auto"><div></div><div>Sleeping over it I have to give -1 to the proposal. However we should consider making explicit casts with "as" to different tuple types with and without labels (separate proposal).</div><div><br></div><div>- Maximilian</div><div><br>Am 05.02.2016 um 08:08 schrieb Taras Zakharko via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>:<br><br></div><blockquote type="cite"><div>The types are clearly different and the current behaviour is fine as it is. <div><br></div><div>However, it would be nice to have more support for tuple types in the language. E.g. I’d expect something like this</div><div><br></div><div> <span style="font-family:Menlo;font-size:11px;color:rgb(187,44,162)">let</span><span style="font-family:Menlo;font-size:11px"> x = (a:</span><span style="font-family:Menlo;font-size:11px;color:rgb(39,42,216)">4</span><span style="font-family:Menlo;font-size:11px">, b:</span><span style="font-family:Menlo;font-size:11px;color:rgb(39,42,216)">5</span><span style="font-family:Menlo;font-size:11px">)</span></div><div><font face="Menlo"><span style="font-size:11px"> let y = x as (m: Int, n: Int)</span></font></div><div><font face="Menlo"><span style="font-size:11px"><br></span></font></div><div><font face="Menlo"><span style="font-size:11px">to work (but it doesn’t currently, you have to use forced cast). </span></font></div><div><font face="Menlo"><span style="font-size:11px"><br></span></font></div><div><font face="Menlo"><span style="font-size:11px">— Taras</span><br></font><div><br><div><blockquote type="cite"><div>On 05 Feb 2016, at 07:47, Ondrej Barina via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><p dir="ltr">-1 for proposal. Current behavior is fine. There is no need to change it<br>
Ondrej b.<br>
</p>
<div class="gmail_quote">On Feb 5, 2016 12:56 AM, "Chris Lattner via swift-evolution" <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
> On Feb 4, 2016, at 3:26 PM, Maximilian Hünenberger <<a href="mailto:m.huenenberger@me.com" target="_blank">m.huenenberger@me.com</a>> wrote:<br>
><br>
> Is this behavior intended?<br>
><br>
> What disadvantage do I have if a conversion from (a: Int, b: Int) to (x: Int, y: Int) is allowed?<br>
<br>
If that were allowed, then it also stands to reason that a conversion from “(a: Int, b : Int)” to “(b: Int, a : Int)” would also work… but would not swap the elements. IMO, it is best to disallow things misleading things like this.<br>
<br>
-Chris<br>
<br>
><br>
><br>
> Thank you for clarification<br>
> - Maximilian<br>
><br>
>> Am 05.02.2016 um 00:11 schrieb Chris Lattner <<a href="mailto:clattner@apple.com" target="_blank">clattner@apple.com</a>>:<br>
>><br>
>><br>
>>> On Feb 4, 2016, at 10:57 AM, Maximilian Hünenberger <<a href="mailto:m.huenenberger@me.com" target="_blank">m.huenenberger@me.com</a>> wrote:<br>
>>><br>
>>> Is there a reasoning behind treating (Int, Int) and (lhs: Int, rhs: Int) as separate types?<br>
>><br>
>> I’m not sure what you mean by “separate types”. One has labels, one does not, so they are clearly separate.<br>
>><br>
>> Further, "(Int, Int)” needs to be compatible/convertible to "(a : Int, b : Int)”, but “(a : Int, b : Int)” should not be convertible to “(x : Int, y : Int)”.<br>
>><br>
>>> Is there a connection to your tuple splat proposal?<br>
>><br>
>> No connection at all.<br>
>><br>
>> -Chris<br>
>><br>
><br>
<br>
_______________________________________________<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" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>
_______________________________________________<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/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div></div></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</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/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></div>_______________________________________________<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/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div></div></div></div></blockquote></div><br></div>_______________________________________________<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/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div></div></div></div></div><br>_______________________________________________<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/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>