Overloading (+)
The only way to overload a name in Haskell is to use type classes, so you have three choices:
- Make
Vector
an instance ofNum
and just have multiplication return anerror
. - Use something like the numeric prelude, which defines more fine-grained numeric classes.
- Pick some other name like
.+.
or something similar for vector addition.
I know that I could make
Vector3
an instance of theNum
typeclass, but that is too restrictive for me; I do not want to define multiplication of a vector by another vector.
That would be the easiest solution, though. You can define multiplication as
(*) = error "vector multiplication not implemented"
Think of the vector operations that you would get for free!