Skip to content

Incorrect constraints given single flexible undecidable instance.

If a class has an instance in the form F a => G a in its file, and no other instances, then the functions in G a will have the constraint F a, rather than G a.

Example file

{-# LANGUAGE FlexibleInstances, UndecidableInstances #-}
class A a where
    f :: a -> a
instance {-# OVERLAPPABLE #-} Eq a => A a where
    f = id

f will have type Eq a => a -> a -> Bool. Consider the functions

g, h, i :: A a => a -> a
g = f
h = let f' = f in f
i = f' where
    f' = f

h and i will both fail to typecheck.

If we add:

instance A Int where
    f = id

Then f will have the correct type A a => a -> a -> Bool.

Edited by JCarr
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information