Type design question
Sun, 27 Jul 2003 22:36:46 -0400
Content-Type: text/plain; charset=us-ascii
On Mon, Jul 28, 2003 at 11:59:48AM +1000, Andrew J Bromage wrote:
> G'day all.
> On Fri, Jul 25, 2003 at 03:48:15PM -0400, Dylan Thurston wrote:
> > Another approach is to make Universe a multi-parameter type class:
> > class (RealFrac a, Floating a) =3D> Universe u a | u -> a where
> > distanceVector :: u -> Vector a -> Vector a -> Vector a
> > ...
> Actually, this is a nice way to represent vector spaces, too:
> class (Num v, Fractional f) =3D> VectorSpace vs v f | vs -> v f where
> scale :: vs -> f -> v -> v
> innerProduct :: vs -> v -> v -> f
> 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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
-----END PGP SIGNATURE-----