<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&lt;Int&gt;. 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">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</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&lt;Int&gt;<br>
<br>
Especially since sets are used so infrequently compared to Array and Dictionary.<br>
Jack<br>
<div class="HOEnZb"><div class="h5">&gt; On Jan 18, 2016, at 1:24 PM, Michael Henson via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br>
&gt;<br>
&gt; 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>
&gt;<br>
&gt; 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>
&gt;<br>
&gt; 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>
&gt;<br>
&gt; Arrays, implicit index:<br>
&gt;<br>
&gt; let array = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]<br>
&gt; var array: [String]<br>
&gt; var empty: [String] = []<br>
&gt;<br>
&gt; Dictionaries, explicit index:<br>
&gt;<br>
&gt; let dictionary = [&quot;a&quot;: 1, &quot;b&quot;: 5, &quot;c&quot;: 9]<br>
&gt; var dictionary: [String: Int]<br>
&gt; var empty: [String: Int] = [:]<br>
&gt;<br>
&gt; Sets, by contrast, have no particular order and no &quot;key&quot;. Even though the Set is enumerable and iterable, it isn&#39;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>
&gt;<br>
&gt; The Set literal could be:<br>
&gt;<br>
&gt; let set = [ _: &quot;a&quot;, &quot;b&quot;, &quot;c&quot; ]<br>
&gt; var set = [ _: String ]<br>
&gt; var empty: [ _: String ] = [_:]<br>
&gt;<br>
&gt; In the grammar:<br>
&gt;<br>
&gt; set-literal -&gt; [ _ : array-literal-items[opt] ]<br>
&gt; literal-expression -&gt; array-literal | dictionary-literal | set-literal<br>
&gt;<br>
&gt; set-type -&gt; [ _ : type ]<br>
&gt; type -&gt; array-type | dictionary-type | set-type | ... etc.<br>
&gt;<br>
&gt;<br>
&gt; Examples:<br>
&gt;<br>
&gt; let x = [ _: &quot;A&quot;, &quot;B&quot;, &quot;C&quot; ]<br>
&gt; let y: [ _: String ] = [ _: ]<br>
&gt;<br>
&gt;<br>
&gt; Alternatives considered:<br>
&gt;<br>
&gt; 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>
&gt;<br>
&gt; Mike<br>
</div></div><div class="HOEnZb"><div class="h5">&gt; _______________________________________________<br>
&gt; swift-evolution mailing list<br>
&gt; <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
&gt; <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>