Skip to content

Type equality constraint not propagated to superclass

The code:

  {-# LANGUAGE TypeFamilies, UndecidableInstances #-}

  -- Demonstrates a bug in propagating type equality constraints

  class VectorSpace v where
    type Scalar v :: *

  class VectorSpace v => InnerSpace v

  instance (VectorSpace u,VectorSpace v, Scalar u ~ Scalar v) => VectorSpace (u,v) where
    type Scalar (u,v) = Scalar u

  instance (InnerSpace u,InnerSpace v, Scalar u ~ Scalar v) => InnerSpace (u,v)

In ghc 6.9.20080622, the last line yields

  Data\TypeEqBug.hs:20: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)'

I'd expect the type equality constraint in the InnerSpace instance to get propagated to the parent class.

By the way, without the UndecidableInstances above, we get:

    Constraint is no smaller than the instance head
      in the constraint: Scalar u ~ Scalar v
    (Use -XUndecidableInstances to permit this)
    In the instance declaration for `VectorSpace (u, v)'
Trac metadata
Trac field Value
Version 6.9
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC conal@conal.net
Operating system Unknown
Architecture Unknown
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information