<div style="white-space:pre-wrap">I'm not sure I understand the inconsistency you see. Set and Dictionary require hashable values and keys, respectively. That's just in the nature of what these types are. Do you want Set itself to conform to Hashable?<br></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Apr 29, 2016 at 12:57 Wolfgang H. via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
A. When trying to declare nested collection types an inconsistency<br>
is unveiled:<br>
<br>
<br>
A.1. “Array” as outer type allows for every collection type as inner<br>
type (“Int” used as a placeholder for “some other type”):<br>
<br>
let test_aa: Array<Array<Int>> = []<br>
// ok<br>
<br>
let test_as: Array<Set<Int>> = []<br>
// ok<br>
<br>
let test_ad: Array<Dictionary<Int, Int>> = []<br>
// ok<br>
<br>
<br>
A.2. “Set” as outer type allows for “Set” as inner type only:<br>
<br>
let test_sa: Set<Array<Int>> = []<br>
// compile time error “Type 'Array<Int>' does not conform to<br>
// protocol 'Hashable'”<br>
<br>
let test_ss: Set<Set<Int>> = []<br>
// ok<br>
<br>
let test_sd: Set<Dictionary<Int, Int>> = []<br>
// compile time error “Type 'Dictionary<Int, Int>' does not<br>
// conform to protocol 'Hashable'”<br>
<br>
<br>
A.3. The same is true for “Dictionary” as outer type:<br>
<br>
let test_da: Dictionary<Array<Int>, Int> = [:]<br>
// compile time error “Type 'Array<Int>' does not conform to<br>
// protocol 'Hashable'”<br>
<br>
let test_ds: Dictionary<Set<Int>, Int> = [:]<br>
// ok<br>
<br>
let test_dd: Dictionary<Dictionary<Int, Int>, Int> = [:]<br>
// compile time error “Type 'Dictionary<Int, Int>' does not<br>
// conform to protocol 'Hashable'”<br>
<br>
<br>
B. When letting Swift infer the type of collections of “Array” from<br>
literals another inconsistency comes to light:<br>
<br>
<br>
B.1. “Array” as outer type behaves IMHO perfectly:<br>
<br>
var testArray = [ [ 1, 2, 4, 8 ], [ 1, 3, 9, 27 ] ]<br>
print(testArray.dynamicType)<br>
// prints “Array<Array<Int>>”<br>
testArray.append( [ 1, "five", 25, 625 ] );<br>
// compile time error “Cannot convert value of 'String' to<br>
// expected element type 'Int'”; type safe<br>
<br>
<br>
B.2. “Set” as outer type works but there is no type safety:<br>
<br>
var testSet: Set = [ [ 1, 2, 4, 8 ], [ 1, 3, 9, 27 ] ]<br>
print(testSet.dynamicType)<br>
// prints “Set<NSArray>”<br>
testSet.insert( [ 1, "five", 25, 625 ] )<br>
// neither run time nor compile time errors; no type safety<br>
<br>
<br>
B.3. The same goes for “Dictionary” as outer type:<br>
<br>
var testDictionary = [<br>
[ 1, 2, 4, 8 ]: "Powers of Two",<br>
[ 1, 3, 9, 27 ]: "Powers of Three",<br>
]<br>
print(testDictionary.dynamicType)<br>
// prints "Dictionary<NSArray, String>"<br>
testDictionary[ [ 1, "five", 25, 625 ] ] = "Powers of Five"<br>
// neither run time nor compile time errors; no type safety<br>
<br>
<br>
<br>
— — - Wolfgang H.<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>