3 ms·
No, what he means is the you would need to write these two functions: func DotProductInt(v1, v2 Vector2D) int { return v1.x*v2.x + v1.y*v2
by gnuvince 12y ago
No, what he means is the you would need to write these two functions:
func DotProductInt(v1, v2 Vector2D) int {
return v1.x*v2.x + v1.y*v2.y
}
func DotProductFloat(v1, v2 Vector2DFloat) float64 {
return v1.x*v2.x + v1.y*v2.y
}
If Go allowed for parametric polymorphism, the type of the elements could be abstracted away like this (not real syntax obviously)
type Vector2D<t> struct {
x, y t
}
func DotProduct(v1, v2 Vector2D<t>) t {
return v1.x*v2.x + v1.y*v2.y
}