Reputation: 331
I have a simple dot product function:
func dotProduct(vectorA: [Float], vectorB: [Float]) -> [Float] {
return map(zip(vectorA, vectorB), *)
}
However, it raises the following error
Ambiguous reference to member '*'
Any ideas? It seems the type of both vectorA and vectorB are explicitly defined as [Float].
Upvotes: 0
Views: 255
Reputation: 7970
It works if call map
on the zipped list:
func dotProduct(vectorA: [Float], vectorB: [Float]) -> [Float] {
return zip(vectorA, vectorB).map(*)
}
Seems Swift's inference is a bit lacking.
Upvotes: 2