How to define an operation in terms of itself (but of different type)?

Hello Haskellers! It's probably a simple question but I can't find a proper solution... Suppose we have a class Vector which overloads (+) operation. I'd like to represent a Matrix data type as a set of vectors: data Matrix3 = M3 !Vector3 !Vector3 !Vector3 In this case (+) for matrices could be implemented as: (M3 r11 r12 r13) + (M3 r21 r22 r23) = M3 (r11 + r21) (r12 + r22) (r13 + r23) But GHC says about ambiguous occurrence. I don't understand why because it's should be pretty clear that rows are vectors and (+) has to be vector type as well. I could use Vector.+ instead but it doesn't look good. Probably I'm missing something. Any ideas? Cheers, Oleksandr.

Seems like all telepath are on vacation, so you would have to show the code. On 24 Jan 2009, at 01:15, Olex P wrote:
Hello Haskellers! It's probably a simple question but I can't find a proper solution... Suppose we have a class Vector which overloads (+) operation. I'd like to represent a Matrix data type as a set of vectors:
data Matrix3 = M3 !Vector3 !Vector3 !Vector3
In this case (+) for matrices could be implemented as:
(M3 r11 r12 r13) + (M3 r21 r22 r23) = M3 (r11 + r21) (r12 + r22) (r13 + r23)
But GHC says about ambiguous occurrence. I don't understand why because it's should be pretty clear that rows are vectors and (+) has to be vector type as well. I could use Vector.+ instead but it doesn't look good. Probably I'm missing something. Any ideas?
Cheers, Oleksandr. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

2009/1/23 Olex P
Hello Haskellers! It's probably a simple question but I can't find a proper solution... Suppose we have a class Vector which overloads (+) operation. I'd like to represent a Matrix data type as a set of vectors:
data Matrix3 = M3 !Vector3 !Vector3 !Vector3
In this case (+) for matrices could be implemented as:
(M3 r11 r12 r13) + (M3 r21 r22 r23) = M3 (r11 + r21) (r12 + r22) (r13 + r23)
But GHC says about ambiguous occurrence. I don't understand why because it's should be pretty clear that rows are vectors and (+) has to be vector type as well. I could use Vector.+ instead but it doesn't look good. Probably I'm missing something. Any ideas?
I'm am seeing an image. It's a... a Vector class, with an operation (+). Oh, he's with another one though. It's the Num class. Oh they're fighting over the (+). Vector is trying to take it from Num, but Num isn't letting go. Why doesn't Vector see that there is a whole pile of operations neglected in the corner, like (^+^), (.+.). He just really wants that (+), huh... Luke
participants (4)
-
Jonathan Cast
-
Luke Palmer
-
Miguel Mitrofanov
-
Olex P