
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) => 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) => 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 inner product. Peace, Dylan