<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">I choose let x: Set = [1, 2, 3, 4] // x inferred to be Set<Int>. The current way. Unless the output of print(a set) change its format.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">zhaoxin</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 19, 2016 at 6:51 AM, Jack Lawrence 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">It doesn’t seem like a big enough win over:<br>
<br>
let x: Set = [1, 2, 3, 4] // x inferred to be Set<Int><br>
<br>
Especially since sets are used so infrequently compared to Array and Dictionary.<br>
Jack<br>
<div class="HOEnZb"><div class="h5">> On Jan 18, 2016, at 1:24 PM, Michael Henson via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
><br>
> Swift currently has literal and type shorthand syntax for native Array and Dictionary types, but not the Set type. It would be useful to have a literal shorthand for Set as well.<br>
><br>
> The existing productions for array and dictionary literals and types share brackets as delimiters, differing only in the contents between the brackets. That poses a slight problem for Set because any syntax, to be useful, must also be easily distinguishable from the other types.<br>
><br>
> Consider that Arrays and Dictionaries are both naturally indexed collections. Arrays by the integer value of the order of items in the collection, usually implicitly, and Dictionaries by the hashed key associated with each value.<br>
><br>
> Arrays, implicit index:<br>
><br>
> let array = ["a", "b", "c"]<br>
> var array: [String]<br>
> var empty: [String] = []<br>
><br>
> Dictionaries, explicit index:<br>
><br>
> let dictionary = ["a": 1, "b": 5, "c": 9]<br>
> var dictionary: [String: Int]<br>
> var empty: [String: Int] = [:]<br>
><br>
> Sets, by contrast, have no particular order and no "key". Even though the Set is enumerable and iterable, it isn't indexed. With that in mind, we can declare that a Set literal or Set type literal should distinguish itself by declaring that it has no index.<br>
><br>
> The Set literal could be:<br>
><br>
> let set = [ _: "a", "b", "c" ]<br>
> var set = [ _: String ]<br>
> var empty: [ _: String ] = [_:]<br>
><br>
> In the grammar:<br>
><br>
> set-literal -> [ _ : array-literal-items[opt] ]<br>
> literal-expression -> array-literal | dictionary-literal | set-literal<br>
><br>
> set-type -> [ _ : type ]<br>
> type -> array-type | dictionary-type | set-type | ... etc.<br>
><br>
><br>
> Examples:<br>
><br>
> let x = [ _: "A", "B", "C" ]<br>
> let y: [ _: String ] = [ _: ]<br>
><br>
><br>
> Alternatives considered:<br>
><br>
> Without literals, declaring a Set type is straightforward, easy to recognize, and not much more verbose. There might not be enough of a difference to justify special syntax in the core language.<br>
><br>
> Mike<br>
</div></div><div class="HOEnZb"><div class="h5">> _______________________________________________<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>
_______________________________________________<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>
</div></div></blockquote></div><br></div>