<div style="white-space:pre-wrap">Ok. Let's say I have a generic protocol P<T> with two methods:<br>func foo()<br>func bar(o:T)<br><br>I have a default implementation of foo, which internally calls bar.<br><br>How would work foo once a class implements P<Int> and P<String>?</div><br><div class="gmail_quote"><div dir="ltr">On Sat, 3 Dec 2016 at 15:26 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_-3691223278462264745bloop_markdown gmail_msg"><p class="gmail_msg">I believe generic protocols could be used as a shortcut for protocols with associated types.</p>
<pre class="gmail_msg"><code class="m_-3691223278462264745swift gmail_msg">// Protocol with associated type
protocol Foo {
associatedtype F
func foo(_ f: F)
}
// Existential
typealias IntFoo = Any<Foo> where F == Int
struct Test : IntFoo {} // error
struct Test : Foo { func foo(_: Int) {…} }
let intFoo: IntFoo = Test() // fine
// SE-0142
protocol IntFooProtocol : Foo where F == Int {}
// Generic protocols
// Autogenerated with all associated types present in the parameter list
protocol GenericFoo<F> : Foo { … }
</code></pre>
<p class="gmail_msg">Instead of creating new protocol for a different subset of types constrained by the where clause, this approach could come really handy. </p>
<p class="gmail_msg">Does it affect stdlib and/or ABI somehow? When SE–0142 is implemented to improve the stdlib, wouldn’t that mean that more types like <code class="gmail_msg">IntFooProtocol</code> from above will spawn? </p>
<p class="gmail_msg"></p></div><div class="m_-3691223278462264745bloop_original_html gmail_msg"></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="m_-3691223278462264745bloop_original_html gmail_msg"><div id="m_-3691223278462264745bloop_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_-3691223278462264745bloop_sign_1480770382034871040" class="m_-3691223278462264745bloop_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_-3691223278462264745bloop_original_html gmail_msg"><p class="m_-3691223278462264745airmail_on gmail_msg">Am 3. Dezember 2016 um 13:47:13, Anders Ha (<a href="mailto:hello@andersio.co" class="gmail_msg" target="_blank">hello@andersio.co</a>) schrieb:</p> <blockquote type="cite" class="m_-3691223278462264745clean_bq gmail_msg"><span class="gmail_msg"><div dir="auto" class="gmail_msg"><div class="gmail_msg"></div><div class="gmail_msg">
<div class="gmail_msg">This is called generalized existentials. It is included in the
Generic Manifesto, has been discussed quite a few times with long
email chains before, and spawned the change to the
`protocol<>` syntax as kinda a precursor. It would be
surprised if Swift 4 Phase 2 doesn't have it given its
popularity.</div>
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg">Regards</div>
<div class="gmail_msg">Anders</div>
<div class="gmail_msg"><br class="gmail_msg">
On 2 Dec 2016, at 20:13, Charles Srstka 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">
<br class="gmail_msg"></div>
<blockquote type="cite" class="gmail_msg">
<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_-3691223278462264745Apple-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_-3691223278462264745Apple-converted-space gmail_msg"> </span><strong class="gmail_msg">Unlikely</strong><span class="m_-3691223278462264745Apple-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_-3691223278462264745Apple-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_-3691223278462264745Apple-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_-3691223278462264745Apple-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_-3691223278462264745Apple-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>
</blockquote>
<blockquote type="cite" class="gmail_msg">
<div class="gmail_msg">
<span class="gmail_msg">_______________________________________________</span><br class="gmail_msg">
<span class="gmail_msg">swift-evolution mailing list</span><br class="gmail_msg">
<span class="gmail_msg"><a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a></span><br class="gmail_msg">
<span class="gmail_msg"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class="gmail_msg">
</div>
</blockquote>
</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>