Skip to content

Improve "Can't unify" error messages from type functions

Consider this example from a Haskell Cafe thread:

data (:|:) a b = Inl a | Inr b

class Ix i where
   type IxMap i :: * -> *
   empty  :: IxMap i [Int]

data BiApp a b c = BiApp (a c) (b c)

instance (Ix l, Ix r) => Ix (l :|: r) where
   type IxMap (l :|: r) = BiApp (IxMap l) (IxMap r)
   empty = BiApp empty empty

This elicits the following confusing error message:

     Couldn't match expected type `IxMap l'
            against inferred type `IxMap i'
       Expected type: IxMap (l :|: r) [Int]
       Inferred type: BiApp (IxMap i) (IxMap i1) [Int]
     In the expression: BiApp empty empty
     In the definition of `empty': empty = BiApp empty empty

As Alexander Dunlap responds, the error message is correct, but I can't help feeling that we should try harder to give a better error message. Something like "Since IxMap is a type function, knowing that IxMap l = IxMap i does not require that l = i". Or something.

This ticket is just to make sure we don't forget. The thread is here http://www.haskell.org/pipermail/haskell-cafe/2008-August/046371.html

Simon

Trac metadata
Trac field Value
Version 6.8.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system Unknown
Architecture Unknown
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information