
I'm converting some code from functionally dependencies to associated types, and I've run into a problem with equality constraints and subclasses. The classes: class AdditiveGroup v => VectorSpace v where type Scalar v :: * (*^) :: Scalar v -> v -> v class VectorSpace v => InnerSpace v where (<.>) :: v -> v -> Scalar v Products of vector spaces are vector spaces *if* over the same scalar field. Hence: instance ( VectorSpace u,VectorSpace v , Scalar u ~ Scalar v ) => VectorSpace (u,v) where type Scalar (u,v) = Scalar u s *^ (u,v) = (s*^u,s*^v) Similarly for inner product spaces: instance ( InnerSpace u,InnerSpace v, Scalar u ~ Scalar v , AdditiveGroup (Scalar v) ) => InnerSpace (u,v) where (u,v) <.> (u',v') = (u <.> u') ^+^ (v <.> v') But here's where ghc-6.9.20080622 balks: Data\VectorSpace.hs:106:0: Couldn't match expected type `Scalar v' against inferred type `Scalar u' When checking the super-classes of an instance declaration In the instance declaration for `InnerSpace (u, v)' Any ideas? - Conal