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

Maximilian Hünenberger m.huenenberger at me.com
Thu Feb 4 11:35:07 CST 2016


+1

Although I think almost all examples are bugs:

// As expected
let a: (lhs: Int, rhs: Int) = (4, 5) // works
(4,5).dynamicType == (lhs: 2, rhs: 6).dynamicType // true
	
	
	
let arr1 = [(lhs: 3, rhs: 5)]
let arr2 = [(1,2)]
	
// == can only be used for equatable element types. Right now Tuples are not equatable
arr1 == arr2
	
	
	
// doesn't work: I assume it is a bug see below
[(lhs: 3, rhs: 5)].dynamicType == [(1,2)].dynamicType
	
let type = [(lhs: 3, rhs: 5)].dynamicType
let type2 = [(1,2)].dynamicType
	
type == type2 // works!	

	

struct Foo<T> {
	let bar: T
}
	
var foo1 = Foo(bar: (4, 5))
var foo2 = Foo(bar: (lhs: 4, rhs: 5))
	
// still an error
foo1 = foo2
// Cannot assign value of type ‘Foo<(lhs: Int, rhs: Int)>’ to type ‘Foo<(Int, Int)>’
	
// As expected
foo1.dynamicType == foo2.dynamicType // true



As summary: Tuples are not equatable , dynamic types of Array literals are buggy , weird generic behavior.

You should file a bug/radar.

Best regards
- Maximilian

> Am 04.02.2016 um 10:10 schrieb David Hart via swift-evolution <swift-evolution at swift.org>:
> 
> 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
> (4,5).dynamicType == (lhs: 2, rhs: 6).dynamicType // true
> 
> But:
> 
> [(lhs: 3, rhs: 5)] == [(1,2)]
> // Binary operator ‘==‘ cannot be applied to operands of type ‘[(las: Int, rhs: Int)]’ and ‘[(Int, Int)]’
> [(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)>'
> 
> 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)>’
> 
> But:
> 
> foo1.dynamicType == foo2.dynamicType // true
> 
> So it seems that in parts of the language, they are treated with the same type, but not in generics.
> 
> Any input?
> _______________________________________________
> 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/f91744af/attachment.html>


More information about the swift-evolution mailing list