<div dir="ltr"><span style="font-family: courier new,monospace;">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:</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> class AdditiveGroup v => VectorSpace v where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> type Scalar v :: *</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (*^) :: Scalar v -> v -> v</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> class VectorSpace v => InnerSpace v where</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (<.>) :: v -> v -> Scalar v</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Products of vector spaces are vector spaces *if* over the same scalar field. Hence:</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> instance ( VectorSpace u,VectorSpace v</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> , Scalar u ~ Scalar v ) => VectorSpace (u,v) where</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> type Scalar (u,v) = Scalar u</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> s *^ (u,v) = (s*^u,s*^v)</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Similarly for inner product spaces:</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> instance ( InnerSpace u,InnerSpace v, Scalar u ~ Scalar v</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> , AdditiveGroup (Scalar v) ) => InnerSpace (u,v) where</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (u,v) <.> (u',v') = (u <.> u') ^+^ (v <.> v')</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">But here's where ghc-6.9.20080622 balks:</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Data\VectorSpace.hs:106:0:</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> Couldn't match expected type `Scalar v'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> against inferred type `Scalar u'</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> When checking the super-classes of an instance declaration</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> In the instance declaration for `InnerSpace (u, v)'</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Any ideas?</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> - Conal</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"></div>