Skip to content

Incorrect behavior with empty functional dependencies

This is a corner case, but it would appear that GHC doesn't do proper improvements for classes with "empty" functional dependencies. Consider the following example:

class C a | -> a where
   m :: a -> ()

instance C Int

f x = m x

The inferred type for f is C a => a -> (), however I was expecting it to infer Int -> ().

The reasoning is as follows: the use of m generates a C a constraint (a is a unification variable). This should have interacted with the C Int instance (in a rather odd vacuous sort of way) to generate a derived constraint a ~ Int, which should have then instantiated a to Int.

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