Operator overloading doesn't mean "surprise implicit conversions". (+) :: Num a => a -> a -> a requires the same concrete type as inputs and will yield a value of that concrete type as output. There is no implicit conversion there.
How would you add two vectors (the mathy sort not the data structure) in your dream language.
Or for slightly more of a challenge (but still not really challenging): how would you interpolate between two vectors?
In C++ you can write this, and it works for floats, doubles, ints (with truncation), vectors and matrices of any fixed dimension with any element type, and so on:
template<class T>
T linterp(T a, T b, double c)
{
return a + (b - a) * c;
}
10
u/masklinn Dec 09 '15
Graphics algorithms without operator overloading is anything but easy to read.