<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I agree that this is a desirable property, but it would only work for literals. In the most general sense, `Hashable` instances are only guaranteed to be comparable for equality at runtime.<div class=""><br class=""></div><div class="">Austin<br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 21, 2016, at 2:09 AM, Rudolf Adamkovic via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto" class=""><div class="">This is a great point. The compiler should emit a warning in case of duplicate values:</div><div class=""><br class=""></div><div class="">let numbers: Set&lt;Int&gt; = [0, 0]<br class=""><br class="">R+<br class=""><br class="">Sent from my iPhone</div><div class=""><br class="">On 19 Jan 2016, at 21:19, Michael Henson via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">It doesn’t seem like a big enough win over:&nbsp;</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">&nbsp;</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">let x: Set = [1, 2, 3, 4] // x inferred to be Set&lt;Int&gt;&nbsp;</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">&nbsp;</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Especially since sets are used so infrequently compared to Array and Dictionary</blockquote><div class=""><br class="">It's true that that works and is easy to understand. The two strongest arguments I can come up with for a Set-specific syntax are:<br class=""><br class=""></div><div class="">1. The Set collection has no duplicate values, but the Array-literal initialization syntax allows them. Disappearing values could lead to difficult-to-diagnose problems. A Set literal type could allow the tools to detect and notify if duplicates are given.</div><div class=""><br class=""></div><div class="">2.&nbsp; This initialization syntax is clear in this particular case, but only because the type declaration is right there. Initializing Sets isn't as obvious when the code is passing an argument to a function or setting the value on structs or classes that have been declared elsewhere.</div><div class=""><br class=""></div><div class="">Mike</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Jan 18, 2016 at 2:51 PM, Jack Lawrence <span dir="ltr" class="">&lt;<a href="mailto:jackl@apple.com" target="_blank" class="">jackl@apple.com</a>&gt;</span> wrote:<br class=""><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 class="">
<br class="">
let x: Set = [1, 2, 3, 4] // x inferred to be Set&lt;Int&gt;<br class="">
<br class="">
Especially since sets are used so infrequently compared to Array and Dictionary.<br class="">
<span class="HOEnZb"><font color="#888888" class="">Jack<br class="">
</font></span><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" class="">swift-evolution@swift.org</a>&gt; wrote:<br class="">
&gt;<br class="">
&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 class="">
&gt;<br class="">
&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 class="">
&gt;<br class="">
&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 class="">
&gt;<br class="">
&gt; Arrays, implicit index:<br class="">
&gt;<br class="">
&gt; let array = ["a", "b", "c"]<br class="">
&gt; var array: [String]<br class="">
&gt; var empty: [String] = []<br class="">
&gt;<br class="">
&gt; Dictionaries, explicit index:<br class="">
&gt;<br class="">
&gt; let dictionary = ["a": 1, "b": 5, "c": 9]<br class="">
&gt; var dictionary: [String: Int]<br class="">
&gt; var empty: [String: Int] = [:]<br class="">
&gt;<br class="">
&gt; 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 class="">
&gt;<br class="">
&gt; The Set literal could be:<br class="">
&gt;<br class="">
&gt; let set = [ _: "a", "b", "c" ]<br class="">
&gt; var set = [ _: String ]<br class="">
&gt; var empty: [ _: String ] = [_:]<br class="">
&gt;<br class="">
&gt; In the grammar:<br class="">
&gt;<br class="">
&gt; set-literal -&gt; [ _ : array-literal-items[opt] ]<br class="">
&gt; literal-expression -&gt; array-literal | dictionary-literal | set-literal<br class="">
&gt;<br class="">
&gt; set-type -&gt; [ _ : type ]<br class="">
&gt; type -&gt; array-type | dictionary-type | set-type | ... etc.<br class="">
&gt;<br class="">
&gt;<br class="">
&gt; Examples:<br class="">
&gt;<br class="">
&gt; let x = [ _: "A", "B", "C" ]<br class="">
&gt; let y: [ _: String ] = [ _: ]<br class="">
&gt;<br class="">
&gt;<br class="">
&gt; Alternatives considered:<br class="">
&gt;<br class="">
&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 class="">
&gt;<br class="">
&gt; Mike<br class="">
</div></div><div class="HOEnZb"><div class="h5">&gt; _______________________________________________<br class="">
&gt; swift-evolution mailing list<br class="">
&gt; <a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class="">
</div></div></blockquote></div><br class=""></div>
</div></blockquote><blockquote type="cite" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></div></body></html>