I don't understand why this is failing:
import Foundation
import simd
protocol TestProtocol {
associatedtype ElementType
func reduce_add(x:Self) -> ElementType
}
extension float2 : TestProtocol {
typealias ElementType=Float
}
I get a "Type 'float2' does not conform to protocol 'TestProtocol'" error in the Playground. Specifically it tells me:
Playground execution failed: Untitled Page.xcplaygroundpage:3:1: error: type 'float2' does not conform to protocol 'TestProtocol' extension float2 : TestProtocol { ^ Untitled
Page.xcplaygroundpage:6:10: note: protocol requires function 'reduce_add' with type 'float2 -> ElementType' func reduce_add(x:Self) -> ElementType
When I look at the simd
interface, however, I see:
/// Sum of the elements of the vector.
@warn_unused_result
public func reduce_add(x: float2) -> Float
and if I call reduce_add(float2(2.4,3.1))
, I get the right result. ElementType is typealias
ed to Float
.
Where am I going wrong here?