2009/1/24 Olex P <[email protected]>

> But you know it doesn't make too much sense because I also have to define
> addition Scalar + Vector (that means construct vector from scalar and add a
> vector), Vector + Scalar and so on. And as we are not able to overload
> operations in C++ like way we have to create several different operations
> even if their meaning is pretty close.


Well, yeah, but their meaning isn't *the same*, so we don't give them the
same name.

For vectors, putting a carat (or other signifier like a dot) on the side of
the operation which has the vector is relatively common practice.

Scalar +^ Vector
Vector ^+^ Vector

And so on.

And also, I wonder, what are you going and adding scalars to vectors for!?
(I've heard of multiplying scalars by vectors -- that's in the definition of
a vector space, but adding...?)

Oh, instead of overloading a million operations that just work
component-wise on vectors the way C++ guys do it, you can just define a
higher-order function:

vmap :: (Vector v) => (Double -> Double) -> v -> v

Or however it works out in your situation.  Then you can reserve those
precious symbols for things that are actually vectory, like inner products.

Luke
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to