<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><blockquote type="cite" class="clean_bq">As we can(as example) expect that in 3rd party code someone will do:&nbsp;<br><br>extension StructA: ExtraProtocol1 {&nbsp;<br>func bar() {}&nbsp;<br>}&nbsp;<br><br>extension StructB: ExtraProtocol2 {&nbsp;<br>func blort() {}&nbsp;<br>}&nbsp;</blockquote></div> <div><br></div>Can we really do that? I mean, I thought about that myself but I came to the conclusion that this scenario is like: I was to lazy to couple this structs to my library protocols, will you do that for me?<div><br></div><div>Sure one could think that this protocols might be optional but the `<span style="font-family: 'helvetica Neue', helvetica;">f(p: MyProtocol)</span>` function will cover this scenario.</div><div><br></div><div>Another interesting side-effect `struct&lt;&gt;`, `class&lt;&gt;` and `enum&lt;&gt;` will allow us to do is to distinguish between value and reference types for generics. I tried this differentiation types with protocols like `AnyReference` and `AnyValue` in another topic before (<a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160502/016286.html"><span style="color: rgb(0, 0, 0);">Should we rename "class" when referring to protocol conformance?</span></a>), but I kinda like this new approach.</div><div><br></div><div>Here is what I mean in detail:</div><div><br></div><div>protocol SomeProtocol /* we can’t constraint it to value types at the moment, only `class`es works */ {}</div><div><br></div><div>func foo&lt;T&gt;(value: struct&lt;T, SomeProtocol&gt;) { /* do some work */ }</div><div><br></div><div>This function is pretty neat. (1) You can force the library user to create a struct with conformance to `SomeProtocol`. (2) This approach will accept any struct which conforms to that protocol.</div><div><br></div><div>As I said in the protocol comment above protocols can only be constrained to classes at the moment, and this might change in the future. If we also had some sort of things for generics so the function from above might have looked like this:</div><div><br></div><div>func foo&lt;T: struct where T: SomeProtocol&gt;(value: T) {}</div><div><br></div><div>But it seems that such a thing won’t ever happen to Swift.</div><div><br></div><div>Basically `struct&lt;&gt;`, `class&lt;&gt;` and `enum&lt;&gt;` will just enable this for us. `all&lt;&gt;` would accept any type at its first element.</div><div><br></div><div>func foo&lt;T /* add more constraints here */ &gt;(value: all&lt;T, SomeProtocol&gt;) { /* T could be a reference type or value type */ }</div><div><br></div><div>That been said, `all&lt;&gt;` could replace `protocol&lt;&gt;` where it is composed from protocols. `all&lt;&gt;` can only be used as a generic constraints if the first element is a protocol or a reference type.</div><div><br></div><div>@Matthew: isn’t this somehow a step towards (generic) `PureValue` types?</div><div><br></div><div>struct A&lt;T&gt; {</div><div><br></div><div>&nbsp; &nbsp; var value: struct&lt;T&gt; // if we drop the strict rule of at least one protocols</div><div>}</div><div><br></div><div>How does it sound to you?</div><div>&nbsp;</div><div> <div id="bloop_sign_1463164748581245952" class="bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">--&nbsp;<br>Adrian Zubarev<br>Sent with Airmail</div></div> <br><p class="airmail_on">Am 13. Mai 2016 bei 20:34:59, Vladimir.S (<a href="mailto:svabox@gmail.com">svabox@gmail.com</a>) schrieb:</p> <blockquote type="cite" class="clean_bq"><span><div><div></div><div>Hmm..
<br>
<br>What about such synthetic scenario:
<br>
<br>at the moment of writing our code we have:
<br>
<br>public protocol MyProtocol {
<br>   func foo()
<br>}
<br>
<br>public struct StructA:MyProtocol {
<br>   func foo()
<br>}
<br>
<br>public struct StructB:MyProtocol {
<br>   func foo()
<br>}
<br>
<br>and have
<br>
<br>public protocol ExtraProtocol1 {
<br>   func bar()
<br>}
<br>
<br>public protocol ExtraProtocol2 {
<br>   func blort()
<br>}
<br>
<br>then we actually can have such code:
<br>
<br>func f(p: MyProtocol) {
<br>   if let a = p as? struct&lt;StructA, ExtraProtocol1&gt; {
<br>      a.foo()
<br>      a.bar()
<br>   }
<br>   else
<br>   if let b = p as? struct&lt;StructB, ExtraProtocol2&gt; {
<br>      b.foo()
<br>      b.blort()
<br>   }
<br>}
<br><br>
<br>
<br>
<br>On 13.05.2016 20:50, Adrian Zubarev via swift-evolution wrote:
<br>&gt;&gt;         'struct&lt;&gt;' does seem redundant unless it becomes subtypeable. If
<br>&gt;&gt;         you want a struct which conforms to several protocols, protocol&lt;&gt;
<br>&gt;&gt;         already covers this.
<br>&gt;&gt;
<br>&gt;&gt;     I think this is not correct. Lets check this example:
<br>&gt;&gt;
<br>&gt;&gt;     func foo(value: SomeProtocol) {
<br>&gt;&gt;
<br>&gt;&gt;         if let a = value as? struct&lt;StructA, SomeProtocol&gt; { /* do
<br>&gt;&gt;     something with a */ }
<br>&gt;&gt;
<br>&gt;&gt;         else if let b = value as? struct&lt;StructB, SomeProtocol&gt; { /* do
<br>&gt;&gt;     something with b */ }
<br>&gt;&gt;
<br>&gt;&gt;     }
<br>&gt;&gt;
<br>&gt;&gt;     In this scenario you’ll be able to access properties and functions
<br>&gt;&gt;     from `StructA` or `StructB` which might not be covered by
<br>&gt;&gt;     `SomeProtocol`. Everything is merged nicely into one instance. But
<br>&gt;&gt;     you are right it depends on the use-case.
<br>&gt;&gt;
<br>&gt;&gt;
<br>&gt;&gt; There is no need to include the protocol here.   Just do this:
<br>&gt;&gt;
<br>&gt;&gt; if let a = value as? StructA { use a }
<br>&gt;&gt;
<br>&gt; Whoops, I forgot that this will do the trick. I apologize for any confusion
<br>&gt; here, you are totally right.
<br>&gt;
<br>&gt; That been said, do we really need `type&lt;&gt;` aka. `all&lt;&gt;` for value types? I
<br>&gt; need to rethink this part of the proposal. Is there any use-case where we
<br>&gt; would need this (any scenario for the future Swift version also counts)?
<br>&gt;
<br>&gt; If we had `all&lt;&gt;` in Swift already for extendable reference types and one
<br>&gt; day structs would become subtypeable, this wouldn’t be a huge problem to
<br>&gt; upgrade `all&lt;&gt;` for structs I guess.
<br>&gt;
<br>&gt; --
<br>&gt; Adrian Zubarev
<br>&gt; Sent with Airmail
<br>&gt;
<br>&gt;
<br>&gt;
<br>&gt; _______________________________________________
<br>&gt; swift-evolution mailing list
<br>&gt; swift-evolution@swift.org
<br>&gt; https://lists.swift.org/mailman/listinfo/swift-evolution
<br>&gt;
<br></div></div></span></blockquote></div></body></html>