[swift-users] Extending Arrays of specific type, and specialization

Rick Mann rmann at latencyzero.com
Tue Nov 22 18:44:12 CST 2016


> On Nov 22, 2016, at 03:39 , Adrian Zubarev <adrian.zubarev at devandartist.com> wrote:
> 
> It’s already fixed for Swift 3.1.
> 
> Here is the change log.

Cool. I wonder when it will appear in a shipping Xcode.

So, dumb question: how do you know that "Element" is the name of the thing you want to constrain? Is it just the name of the thing in angle brackets in the declaration of Array? 

I still find this more intuitive and legible. Could it be added as an alternative? Does that pollute the language?

    extension Array<Double> {}

Forgive me if that was already discussed and dismissed.

> 
> 
> 
> 
> -- 
> Adrian Zubarev
> Sent with Airmail
> 
> Am 22. November 2016 um 01:32:42, Rick Mann via swift-users (swift-users at swift.org) schrieb:
> 
>> My googling is not turning up an answer that works in Xcode 8.1. I'd like to do this:
>> 
>> 
>> import Accelerate
>> 
>> extension
>> Array
>> where Element == Double
>> {
>> func
>> sum()
>> -> Double
>> {
>> var result: Double = 0.0
>> vDSP_sveD(self, 1, &result, vDSP_Length(self.count))
>> return result
>> }
>> }
>> 
>> But I get "same-type requirement makes generic parameter 'Element' non-generic."
>> 
>> Also, will there ever be any way to specialize something like
>> 
>> let numbers: [Double] = ...
>> let sum = numbers.reduce(0.0, +)
>> 
>> Into a call to vDSP_sveD()? Would it require compiler optimizations for Accelerate?
>> 
>> Thanks!
>> 
>> -- 
>> Rick Mann
>> rmann at latencyzero.com
>> 
>> 
>> _______________________________________________
>> swift-users mailing list
>> swift-users at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users


-- 
Rick Mann
rmann at latencyzero.com




More information about the swift-users mailing list