<div dir="ltr">I think the pattern here is<div><br></div><div>protocol DoubleProtocol {</div><div> var doubleValue: Double { get }</div><div>}</div><div>extension Double: DoubleProtocol {</div><div> var doubleValue: Double { return self }</div><div>}</div><div>extension Array where Element: DoubleProtocol {</div><div> // in these methods, use the element's .doubleValue property </div><div> // to get the actual double, on which you can then call Double's methods</div><div>}</div><div><br></div><div>That way, if another type wants to conform to DoubleProtocol, it needs to be able to represent itself as a Double.</div><div><br></div><div>-Alex</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 8, 2015 at 4:26 PM, Tuur Anton via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Actually, I just realized that your solution isn't at all what I'm after.
<div>
<br>
</div>
<div>
Doing "extension Array<Double>" is not the same thing and wouldn't be just a "syntactic sugar" for the code you came up with.
<div>
<br>
</div>
<div>
Why? Because in your code, the extension method only knows that the array's Element is a DoubleProtocol. It doesn't know it's a *Double* (which is what I want it to be). As such, it won't have access to Double's methods and such.
</div>
<div>
<br>
</div>
<div>
This is probably okay for Doubles, but for other types, especially my own custom types with their own methods, the difference is huge. "extension Array<MyStructType>" is what I want, but your solution won't help me if the extension method needs access to MyStructType's methods.
</div>
<div>
<br>
</div>
<div>
See what I mean, or am I missing something here?
<br><span class="">
<br> --
<br> Securely sent with Tutanota. Claim your encrypted mailbox today!
<br>
<a href="https://tutanota.com" target="_blank">https://tutanota.com</a>
<br>
<br>7. Dec 2015 13:14 by
<a href="mailto:krzysztof@siejkowski.net" target="_blank">krzysztof@siejkowski.net</a>:
<br>
<br>
</span><blockquote style="border-left:1px solid #93a3b8;padding-left:10px;margin-left:5px"><div><div class="h5">
<div style="font-family:"helvetica","arial";font-size:13px;color:rgba(0,0,0,1.0);margin:0px">
Concerning extension constraining, it’s already doable with:
</div>
<div style="font-family:"helvetica","arial";font-size:13px;color:rgba(0,0,0,1.0);margin:0px">
<br>
</div>
<div style="font-family:"helvetica","arial";font-size:13px;color:rgba(0,0,0,1.0);margin:0px">
```
</div>
<div style="margin:0px">
<div style="margin:0px">
protocol DoubleProtocol {}
</div>
<div style="margin:0px">
<br>
</div>
<div style="margin:0px">
extension Double : DoubleProtocol {}
</div>
<div style="margin:0px">
<br>
</div>
<div style="margin:0px">
extension Array where Element : DoubleProtocol {
</div>
<div style="margin:0px">
func onlyForDoubles() -> String {
</div>
<div style="margin:0px">
return "hello doubles!"
</div>
<div style="margin:0px">
}
</div>
<div style="margin:0px">
}
</div>
<div style="margin:0px">
<br>
</div>
<div style="margin:0px">
[1.2].onlyForDoubles() // „hello doubles!”
</div>
<div style="margin:0px">
["a"].onlyForDoubles() // error: type of expression is ambiguous without more context
</div>
<div style="margin:0px">
```
</div>
<div style="margin:0px">
<br>
</div>
<div style="margin:0px">
However, I personally like the idea of making a syntactic sugar for that case.
</div>
<div style="margin:0px">
<br>
</div>
<div style="margin:0px">
All the best,
</div>
<div style="margin:0px">
Krzysztof
</div>
</div>
<br>
<div></div>
<br>
<p>On 7 December 2015 at 13:01:11, Krzysztof Siejkowski (<a href="mailto:krzysztof@siejkowski.net" target="_blank">krzysztof@siejkowski.net</a>) wrote:</p>
<blockquote style="border-left:1px solid #93a3b8;padding-left:10px;margin-left:5px">
<div style="word-wrap:break-word">
<div></div>
<div>
</div>
</div>
</blockquote>
<div style="font-family:"helvetica","arial";font-size:13px;color:rgba(0,0,0,1.0);margin:0px">
Concerning generic typealiases, the topic is already being discussed in „Generic `typealias`s” thread:
<a href="https://lists.swift.org/pipermail/swift-evolution/2015-December/000132.html" target="_blank">https://lists.swift.org/pipermail/swift-evolution/2015-December/000132.html</a>. The core Swift team approves:
</div>
<div>
<div style="margin:0px">
<br>
</div>
<div style="margin:0px">
>
<span style="white-space:pre-wrap">Yes, this is definitely something that I (at least) would like to see. Patches welcome :-)</span>
</div>
<div style="margin:0px">
> Chris (Lattner)
</div>
<div style="margin:0px">
<br>
</div>
<div style="margin:0px">
All the best,
</div>
<div>
Krzysztof
</div>
<div>
<br>
</div>
</div>
<p>On 7 December 2015 at 12:41:05, Tuur Anton via swift-evolution (<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>) wrote:</p>
</div></div><blockquote style="border-left:1px solid #93a3b8;padding-left:10px;margin-left:5px">
<div>
<div><div><div class="h5">
<div>
Can you please add these features in Swift 3?
</div>
<div>
<br>
</div>
<div>
1. The ability to do this:
</div>
<div>
extension Array<Double> {
</div>
<div>
//extend arrays of doubles
</div>
<div>
}
</div>
<div>
<br>
</div>
<div>
2. Generic typealiases:
</div>
<div>
struct Foo<T,V> {
</div>
<div>
let t: T
</div>
<div>
let v: V
</div>
<div>
}
</div>
<div>
typealias IntFoo<V> = Foo<Int,V> //Error in Swift 2.1
</div>
</div></div><img src="http://graphics/ion-alert-circled.svg" alt="" width="1" height="1" border="0" style="min-height:1px;width:1px;border-width:0;margin-top:0;margin-bottom:0;margin-right:0;margin-left:0;padding-top:0;padding-bottom:0;padding-right:0;padding-left:0"> _______________________________________________
<br><span class=""> 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>
</span></div>
</div>
</blockquote>
</blockquote>
</div>
</div>
<div style="margin-top:10px;font-size:12px;font-family:Helvetica,Arial;color:#999">
Untracked with
<a style="color:#999" href="https://trackbuster.com/?sig" target="_blank">Trackbuster</a>
</div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">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>