[swift-evolution] [Discussion] Removing tuple labels from the type signature

Maximilian Hünenberger m.huenenberger at me.com
Thu Feb 4 12:57:25 CST 2016


Is there a reasoning behind treating (Int, Int) and (lhs: Int, rhs: Int) as separate types?

Should it be treated as the same type as the proposal suggests?

Is there a connection to your tuple splat proposal?

Thank you in advance for clarification :)
- Maximilian

> Am 04.02.2016 um 18:27 schrieb Chris Lattner via swift-evolution <swift-evolution at swift.org>:
> 
> 
>> On Feb 4, 2016, at 1:10 AM, David Hart via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> Before I start working on a proposal, I’d like to understand the problem in detail. Can someone help me understand why parts of the language treats tuple labels as type and other not?
>> 
>> let a: (lhs: Int, rhs: Int) = (4, 5) // works
> 
> This is supposed to work because of an implicit conversion.
> 
>> (4,5).dynamicType == (lhs: 2, rhs: 6).dynamicType // true
> 
> This is not supposed to behave this way.  The bug here is that we’re not encoding tuple labels in the metadata record for tuples.
> 
>> But:
>> 
>> [(lhs: 3, rhs: 5)] == [(1,2)]
>> // Binary operator ‘==‘ cannot be applied to operands of type ‘[(las: Int, rhs: Int)]’ and ‘[(Int, Int)]’
> 
> This is correctly rejected.
> 
>> [(lhs: 3, rhs: 5)].dynamicType == [(1,2)].dynamicType
>> // Binary operator ‘==‘ cannot be applied to operands of type ‘Array<(las: Int, rhs: Int)>.Type’ and ‘Array<(Int, Int)>’
> 
> This is correctly rejected.
> 
> 
>> And:
>> 
>> struct Foo<T> {
>> 	let bar: T
>> }
>> 
>> var foo1 = Foo(bar: (4, 5))
>> var foo2 = Foo(bar: (lhs: 4, rhs: 5))
>> foo1 = foo2
>> // Cannot assign value of type ‘Foo<(las: Int, res: Int)>’ to type ‘Foo<(Int, Int)>’
> 
> This is correctly rejected.
> 
>> But:
>> 
>> foo1.dynamicType == foo2.dynamicType // true
> 
> Same problem: reflection metadata isn’t being encoded, so these end up looking like they have the same dynamic type, when they shouldn’t.
> 
> -Chris
> 
> _______________________________________________
> 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/20160204/da431271/attachment.html>


More information about the swift-evolution mailing list