Hal Daume t-hald@microsoft.com
Wed, 9 Jul 2003 08:11:23 -0700

```What you want to do is make your Vector an instance of the Num(eric)
type class.  For instance:

instance Num Vector where
(+) v1 v2 =3D zipWith (+) v1 v2
(-) v1 v2 =3D zipWith (-) v1 v2
negate v1 =3D map negate v1
abs v1 =3D map abs v1
(*) v1 v2 =3D ...
fromInteger i =3D ...
signum v1 =3D ...

I've left the last three blank because it's unclear what should go
there.  Since (*) has type Vector->Vector->Vector (in this instance),
you can't use dot product or something like that.

signum :: Vector->Vector could be written and just return [-1],  or
, I suppose.

fromInteger :: Integer->Vector is a little harder.  Perhaps just
'fromInteger i =3D [fromInteger i]' would be acceptable.  Or you could
leave these undefined.

--
Hal Daume III                                   | hdaume@isi.edu
"Arrest this man, he talks in maths."           | www.isi.edu/~hdaume

> -----Original Message-----
> Sent: Wednesday, July 09, 2003 7:25 AM
>=20
>=20
> I've learned haskell months, but I still can't understand the=20
> type system very well.
> I can only write:
> -----------------------------------
> type Vector =3D [Double]
> v1 `vadd` v2 =3D zipWith (+) v1 v2
> v1 `vsub` v2 =3D zipWith (-) v1 v2
> svmul :: Double->Vector->Vector
> s `svmul` v =3D map (s*) v
> ------------------------------------
> Tough it works, it is not convenient to use. How to create a=20
> mathematical operators?=20