<div dir="ltr">I actually like &quot;any&lt;P1, P2&gt;&quot;. It does provide that very distinctive visual signal that any&lt;&gt; is not a generic type, and that &#39;any&#39; is not itself a type, but rather a special keyword for constructing an existential:<div><br></div><div>Array&lt;Int&gt;  // a generic type, Array, containing integers</div><div>any&lt;P1, P2&gt; // a protocol composition of two protocols</div><div><br></div><div>In this case, would we want to support &quot;any&lt;&gt;&quot; in addition to Any? The parsing issues should go away, since these are two different identifiers.</div><div><br></div><div>Austin</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 20, 2016 at 12:04 PM, Matthew Johnson <span dir="ltr">&lt;<a href="mailto:matthew@anandabits.com" target="_blank">matthew@anandabits.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class=""><blockquote type="cite"><div>On May 20, 2016, at 2:00 PM, Austin Zheng via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div dir="ltr">I think you should submit this for review, but I also think you should take the part of your older proposal to add class support to Any&lt;...&gt; and submit it as a separate proposal. (I mean, the part where you can define things like &quot;Any&lt;UIViewController, Protocol&gt;&quot; or &quot;Any&lt;class, Protocol&gt;&quot;.)<div><br></div><div>Yes, it is additive, but even getting that feature into Swift 3 would be an enormous benefit if it can be implemented easily. And the core team is probably better positioned than anyone else to determine whether that&#39;s true.</div></div></div></blockquote><div><br></div></span><div>Austin, what is your thought on switching to `any` rather than `Any` since it does not behave like a user-defined generic type?  The convention is for types to be uppercase and keywords to be lowercase.  This falls more into the category of a keyword and has its own behavior distinct from the behavior of all generic types.  Making it stand out syntactically will help to make that clear.</div><div><div class="h5"><br><blockquote type="cite"><div><div dir="ltr"><div><br></div><div>Austin</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 20, 2016 at 2:39 AM, Adrian Zubarev 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"><div style="word-wrap:break-word"><div><div><br></div></div><div><div style="font-family:Helvetica,Arial;font-size:13px;margin:0px">This is a follow up proposal to <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0095-any-as-existential.md" target="_blank"><span>SE-0095</span></a> which should be considered for Swift 3 if SE-0095 will be accepted.</div><div style="font-family:Helvetica,Arial;font-size:13px;margin:0px"><br></div><div style="font-family:Helvetica,Arial;font-size:13px;margin:0px">Here is the formatted draft: <a href="https://github.com/DevAndArtist/swift-evolution/blob/master/proposals/nnnn-ban-redundancy-in-any-existential.md" target="_blank">https://github.com/DevAndArtist/swift-evolution/blob/master/proposals/nnnn-ban-redundancy-in-any-existential.md</a></div><div style="font-family:Helvetica,Arial;font-size:13px;margin:0px"><br></div><div style="font-family:Helvetica,Arial;font-size:13px;margin:0px">Please provide your feedback in this thread, and don’t make a race who is making a better proposal on the exact same topic.</div><div style="font-family:Helvetica,Arial;font-size:13px;margin:0px"><br></div><div style="font-family:Helvetica,Arial;font-size:13px;margin:0px">If you spot any types or other mistakes I’d be happy to see you pointing me to them. ;)</div><div style="font-family:Helvetica,Arial;font-size:13px;margin:0px"><br></div><div><div style="font-family:helvetica,arial;font-size:13px">-- <br>Adrian Zubarev<br>Sent with Airmail</div></div></div><div><div><br></div>

<h1>Disallow redundant <code>Any&lt;...&gt;</code> constructs</h1>

<ul>
<li>Proposal: <a href="https://github.com/apple/swift-evolution/blob/master/proposals/NNNN-name.md" target="_blank">SE-NNNN</a></li>
<li>Author: <a href="https://github.com/DevAndArtist" target="_blank">Adrian Zubarev</a></li>
<li>Status: <a>Awaiting review</a></li>
<li>Review manager: TBD</li>
</ul>

<h2>Introduction</h2><p>This is a follow up proposal to <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0095-any-as-existential.md" target="_blank">SE–0095</a>, if it will be accepted for Swift 3. The current concept of <code>Any&lt;...&gt;</code> introduced in SE–0095 will allow creation of redundant types like <code>Any&lt;A&gt; == A</code>. I propose to disallow such redundancy in Swift 3 to prevent breaking changes in a future version of Swift.</p><p>Swift-evolution thread: <a>[Proposal] Disallow redundant <code>Any&lt;...&gt;</code> constructs</a></p>

<h2>Motivation</h2><p>If SE–0095 will be accepted there will be future proposals to enhance its capabilities. Two of these will be <strong>Any-type requirement</strong> (where <em>type</em> could be <code>class</code>, <code>struct</code> or <code>enum</code>) and <strong>Class requirement</strong>. Without any restrictions these will introduce more redundancy. </p><p>As said before it is possible to create redundant types like <code>Any&lt;A&gt; == A</code> or endless shadowed redundant nesting:</p>

<pre><code>typealias A_1 = Any&lt;A&gt;
typealias A_2 = Any&lt;A_1&gt;
typealias A_3 = Any&lt;A_2&gt;
/* and so on */
</code></pre><p>This proposal should ban redundancy right from the beginning. If there might be any desire to relax a few things, it won’t introduce any breaking changes for <code>Any&lt;...&gt;</code> existential.</p>

<h2>Proposed solution</h2>

<ol>
<li><p>If empty <code>Any&lt;&gt;</code> won’t be disallowed in SE–0095, we should disallow nesting empty <code>Any&lt;&gt;</code> inside of <code>Any&lt;...&gt;</code>.</p></li>
<li><p>Disallow nesting <code>Any</code> (type refers to current <code>typealias Any = protocol&lt;&gt;</code>) inside of <code>Any&lt;...&gt;</code>.</p></li>
<li><p>Disallow <code>Any&lt;...&gt;</code> containing a single <code>Type</code> like <code>Any&lt;Type&gt;</code>.</p><p>The first three rules will ban constructs like <code>Any&lt;Any&lt;&gt;, Type&gt;</code> or <code>Any&lt;Any, Type&gt;</code> and force the developer to use <code>Type</code> instead.</p></li>
<li>Disallow nesting a single <code>Any&lt;...&gt;</code> inside another <code>Any&lt;...&gt;</code>.

<ul>
<li>e.g. <code>Any&lt;Any&lt;FirstType, SecondType&gt;&gt;</code></li>
</ul></li>
<li><p>Disallow same type usage like <code>Any&lt;A, A&gt;</code> or <code>Any&lt;A, B, A&gt;</code> and force the developer to use <code>A</code> or <code>Any&lt;A, B&gt;</code> if <code>A</code> and <code>B</code> are distinct.</p></li>
<li><p>Disallow forming redundant types when the provided constraints are not independent.</p>

<pre><code>// Right now `type` can only be `protocol` but in the future Any&lt;...&gt;  
// could also allow `class`, `struct` and `enum`.
// In this example `B` and `C` are distinct.
type A: B, C {}  
     
// all following types are equivalent to `A`
Any&lt;A, Any&lt;B, C&gt;&gt;
Any&lt;Any&lt;A, B&gt;, C&gt;
Any&lt;Any&lt;A, C&gt;, B&gt;
Any&lt;A, B, C&gt;
Any&lt;A, B&gt;
Any&lt;A, C&gt;
</code></pre>

<ul>
<li><p>If all contraints form a known <code>Type</code> provide a <code>Fix-it</code> error depending on the current context. If there is more than one <code>Type</code>, provide all alternatives to the developer.</p></li>
<li><p>Using <code>Any&lt;...&gt;</code> in a generic context might not produce a <code>Fix-it</code> error:</p>

<pre><code>protocol A {}
protocol B {}
protocol C: A, B {}
         
// there is no need for `Fix-it` in such a context
func foo&lt;T: Any&lt;A, B&gt;&gt;(value: T) {}
</code></pre></li>
</ul></li>
</ol>

<h2>Impact on existing code</h2><p>These changes will break existing code. Projects abusing <code>Any&lt;...&gt;</code> to create redundant types should be reconsidered of usings the equivalent <code>Type</code> the compiler would infer. One would be forced to use <code>A</code> instead of <code>Any&lt;A&gt;</code> for example. A <code>Fix-it</code> error message can help the developer to migrate his project.</p>

<h2>Alternatives considered</h2>

<ul>
<li>Leave redundancy as-is for Swift 3 and live with it.</li>
<li>Deprecate redundancy in a future version of Swift, which will introduce breaking changes.</li></ul></div></div><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>
<br></blockquote></div><br></div>
_______________________________________________<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" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div></div></div><br></div></blockquote></div><br></div>