Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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
        }


Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: