<div style="white-space:pre-wrap">Love it. I have one concern, though. How do we resolve conflicting associated types once several protocols get applied to a class or a struct?</div><br><div class="gmail_quote"><div dir="ltr">On Sat, 3 Dec 2016 at 11:00 Adrian Zubarev via swift-evolution <<a href="mailto:swift-evolution@swift.org">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"><div style="word-wrap:break-word" class="gmail_msg"><div class="m_-1844893608273642092bloop_markdown gmail_msg"><p class="gmail_msg">I think I might found a solution that will satisfy generic protocols and not break the system.</p>
<p class="gmail_msg">The generics manifesto shows two features that are requested from generic protocols.</p>
<p class="gmail_msg">The first feature is needed to reuse the same protocol multiple types like <code class="gmail_msg">struct A : Proto<B>, Proto<C></code>.</p>
<p class="gmail_msg">With SE–0142 we can actually achieve this behavior by creating new protocols and set a subset of the associated types from its parent super protocol.</p>
<p class="gmail_msg">Now we can use this trick to solve the problem from above and create two new protocols and use them as we previously wanted <code class="gmail_msg">struct A : ProtoB, ProtoC</code>. While this is great and solves my issue I’d like to pitch a shortcut for this.</p>
<p class="gmail_msg">Protocols with associated types are kinda generic, but they still need SE–0142 to specify all the associated types.</p>
<p class="gmail_msg">How about making all protocols that contain associated types to also have a shortcut generic protocol that specifies all the associated type in its generic parameter list?</p>
<p class="gmail_msg">Some first bikeshedding:</p>
<pre class="gmail_msg"><code class="m_-1844893608273642092swift gmail_msg">protocol MyStringCollection : Collecntion where Iterator.Element == String, Index == Int {}
protocol Collection<ElementType, IndexType> : Collection {
typealias Iterator.Element = ElementType
typealias Index = IndexType
}
</code></pre>
<p class="gmail_msg">But instead of creating these types by yourself, the compiler would autogenerate these for any protocol that have a list of associated types. To prevent collision between protocol names like <code class="gmail_msg">Collection</code> vs. <code class="gmail_msg">Collection<ParamList></code> one could automatically prefix the generated procols with <code class="gmail_msg">Generic</code>.</p>
<p class="gmail_msg"><code class="gmail_msg">Collection</code> will generate <code class="gmail_msg">GenericCollection<Element, Index></code></p>
<p class="gmail_msg">This would be a huge shortcut for the feature introduced in SE–0142.</p>
<p class="gmail_msg">What does the community think about this idea? </p>
<p class="gmail_msg"></p></div><div class="m_-1844893608273642092bloop_original_html gmail_msg"></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="m_-1844893608273642092bloop_original_html gmail_msg"><div id="m_-1844893608273642092bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto" class="gmail_msg"><br class="gmail_msg"></div> <br class="gmail_msg"> <div id="m_-1844893608273642092bloop_sign_1480752646835070976" class="m_-1844893608273642092bloop_sign gmail_msg"><div style="font-family:helvetica,arial;font-size:13px" class="gmail_msg">-- <br class="gmail_msg">Adrian Zubarev<br class="gmail_msg">Sent with Airmail</div></div> <br class="gmail_msg"></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="m_-1844893608273642092bloop_original_html gmail_msg"><p class="m_-1844893608273642092airmail_on gmail_msg">Am 2. Dezember 2016 um 20:13:50, Charles Srstka (<a href="mailto:cocoadev@charlessoft.com" class="gmail_msg" target="_blank">cocoadev@charlessoft.com</a>) schrieb:</p> <blockquote type="cite" class="m_-1844893608273642092clean_bq gmail_msg"><span class="gmail_msg"><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"></div><div class="gmail_msg">
<blockquote type="cite" class="gmail_msg">On Dec 2, 2016, at 12:34 PM,
Adrian Zubarev via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>> wrote:<br class="gmail_msg"></blockquote>
<div class="gmail_msg">
<blockquote type="cite" class="gmail_msg"><br class="m_-1844893608273642092Apple-interchange-newline gmail_msg">
<div class="gmail_msg">
<p style="margin:15px 0px;font-family:Helvetica,Arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg">I just overlooked that the subsection about generic
protocols was inside the<span class="m_-1844893608273642092Apple-converted-space gmail_msg"> </span><strong class="gmail_msg">Unlikely</strong><span class="m_-1844893608273642092Apple-converted-space gmail_msg"> </span>section.</p>
<p style="margin:15px 0px;font-family:Helvetica,Arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg">The problem is that I need a way to refer to a function
with a specific name. Plus the connection type has to have a
specific API, like having a DispatchQueue and know the router
object if there is any (sounds like a protocol right?!). The
function reference should also keep the connection object alive
with a strong reference.<span class="m_-1844893608273642092Apple-converted-space gmail_msg"> </span></p>
<p style="margin:15px 0px;font-family:Helvetica,Arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg"><code style="font-family:Menlo,Consolas,'Liberation Mono',Courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal" class="gmail_msg">associatedtype</code><span class="m_-1844893608273642092Apple-converted-space gmail_msg"> </span>does not solve that problem
for me.</p>
<p style="margin:15px 0px;font-family:Helvetica,Arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg">I clearly see that generic protocols overlap
with<span class="m_-1844893608273642092Apple-converted-space gmail_msg"> </span><code style="font-family:Menlo,Consolas,'Liberation Mono',Courier,monospace;font-size:10pt;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-color:rgb(248,248,248);color:inherit;border:1px solid rgb(234,234,234);margin:0px 2px;padding:0px 5px;word-break:normal;word-wrap:normal" class="gmail_msg">associatedtype</code><span class="m_-1844893608273642092Apple-converted-space gmail_msg"> </span>but couldn’t we find a
compromise here? For instance like Chris Lattner introduced generic
type aliases without the ability of constants.</p>
</div>
</blockquote>
</div>
<div class="gmail_msg">Why don’t we just use angle brackets to specify
associated types? Protocols aren’t using them for anything anyway.
Then you could:</div>
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg">if let someSequence as? Sequence<Iterator.Element
== Int> { // do something }</div>
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg">which would form a nice parallel to the syntax for
casting things to generic types.</div>
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg">Charles</div>
<div class="gmail_msg"><br class="gmail_msg"></div>
</div></div></span></blockquote></div></div>_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>