9 Jul
2003
9 Jul
'03
3:40 p.m.
On Wednesday, 2003-07-09, 17:11, CEST, Hal Daume wrote:
What you want to do is make your Vector an instance of the Num(eric) type class.
It would be better to define one's own operators instead of using + and - because Vector has no meaningful instance of Num (as Jerzy Karczmarczuk already pointed out). But maybe it's overkill to define a new class if you don't want the same operators for other types.
For instance:
instance Num Vector where (+) v1 v2 = zipWith (+) v1 v2 (-) v1 v2 = zipWith (-) v1 v2
You can also use the nice infix syntax in definitions (as you already did with your `vadd` and `vsub`): v1 + v2 = zipWith (+) v1 v2 v1 - v2 = zipWith (-) v1 v2
[...]
Wolfgang