Bug in type equality constraints?

Conal Elliott conal at conal.net
Tue Jul 15 10:59:25 EDT 2008


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20080715/67380455/attachment.htm


More information about the Glasgow-haskell-users mailing list