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. Probably it's possible with ad hoc overloading but I don't know is it good idea.
What about making your Vector a instance of Num? you have + and * well defined , although * is not commutative in this case2009/1/24 Olex P <hoknamahn@gmail.com>
Yeah guys. I confused myself. I forgot why I had to implement several "+" operators (^+^, ^+, ^+. etc.) for Vector class. Now I've got an idea again. Different names make a perfect sense.
Thanks a lot.On Sat, Jan 24, 2009 at 6:34 AM, Luke Palmer <lrpalmer@gmail.com> wrote:
2009/1/23 Brandon S. Allbery KF8NH <allbery@ece.cmu.edu>
On 2009 Jan 23, at 17:58, Olex P wrote:class Vector v where
(^+^) :: v -> v -> vclass Matrix m where
(^+^) :: m -> m -> mYou can't reuse the same operator in different classes. Vector "owns" (^+^), so Matrix can't use it itself. You could say> instance Matrix m => Vector m where> (^+^) = ...
No you can't! Stop thinking you can do that!
It would be sane to do:
class Vector m => Matrix m where
-- matrix ops that don't make sense on vector
Thus anything that implements Matrix must first implement Vector. Which is sane because matrices are square vectors with some additional structure, in some sense.
Luke
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe