[swift-evolution] Proposal: Implement == and < for tuples where possible, up to some high arity

Dmitri Gribenko gribozavr at gmail.com
Mon Dec 7 18:08:32 CST 2015


On Mon, Dec 7, 2015 at 4:06 PM, Chris Lattner <clattner at apple.com> wrote:
>
> On Dec 7, 2015, at 3:04 PM, Jacob Bandes-Storch <jtbandes at gmail.com> wrote:
>
> On Mon, Dec 7, 2015 at 3:01 PM, Chris Lattner via swift-evolution
> <swift-evolution at swift.org> wrote:
>>
>> On Dec 7, 2015, at 12:01 PM, Dmitri Gribenko via swift-evolution
>> <swift-evolution at swift.org> wrote:
>>
>> I personally don't see a point in going as high as 12 tuple elements.
>> About 4 or 5 makes sense to me.  Given that Swift does not have variadic
>> generics right now, these long tuples have to be defined by someone
>> manually.  If one is defining a tuple that is that long, I'd argue that they
>> should be using a custom struct instead.
>>
>>
>> I tend to agree with Dmitri here.  Independent of the code size concern,
>> what is the expected use-case for > 4 element tuples?
>>
>> -Chris
>
>
>
> On the contrary, I think >4-element-tuples are useful exactly *for* the case
> of custom structs. You wouldn't want the tuples themselves to be part of
> your API, but if you have a custom struct with 4+ Comparable fields, you can
> implement its < operator as simply "return (a1,b1,c1,d1,e1) <
> (a2,b2,c2,d2,e2)”.
>
>
> Sure, or:
>    return (a1,b1,(c1,d1,e1)) < (a2,b2,(c2,d2,e2))

That won't work, since tuples don't conform to Comparable.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/


More information about the swift-evolution mailing list