Type design question

Dylan Thurston dpt@math.harvard.edu
Sun, 27 Jul 2003 22:36:46 -0400


--uAKRQypu60I7Lcqm
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Jul 28, 2003 at 11:59:48AM +1000, Andrew J Bromage wrote:
> G'day all.
>=20
> On Fri, Jul 25, 2003 at 03:48:15PM -0400, Dylan Thurston wrote:
>=20
> > Another approach is to make Universe a multi-parameter type class:
> >=20
> > class (RealFrac a, Floating a) =3D> Universe u a | u -> a where
> >   distanceVector :: u -> Vector a -> Vector a -> Vector a
> > ...
>=20
> Actually, this is a nice way to represent vector spaces, too:
>=20
> 	class (Num v, Fractional f) =3D> VectorSpace vs v f | vs -> v f where
> 	    scale :: vs -> f -> v -> v
> 	    innerProduct :: vs -> v -> v -> f
>=20
> The reason why you may want to do this is that you may in general want
> different inner products on the same vectors, which result in different
> vector spaces.

Hmm, that's an interesting technique, which I'll have to try out; there
are several instances where you want different versions of the same
structure on some elements.  This is an interesting alternative to
newtype wrapping or some such.

However, I would be sure to distinguish between an inner product space
and a vector space.  A vector space has only the 'scale' operation above
(beyond the +, -, and 0 from Num); you will rarely want to have
different versions of the scale operation for a given set of vectors and
base field.  An inner product space has the 'innerProduct' operation you
mention; as you say, there is very frequently more than one interesting
inner product.

Peace,
	Dylan

--uAKRQypu60I7Lcqm
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/JIw+Veybfhaa3tcRAqJqAKCKlIEch+yO8BfaWQnx6nI5iFNjRACeI16A
FfMK9paJHNiULgEz5+jaUvA=
=ElV4
-----END PGP SIGNATURE-----

--uAKRQypu60I7Lcqm--