Skip to content

Suggest "Possible fix: turn on -XImpredicativeTypes" for error number 91028

Consider the following example:

{-# LANGUAGE RequiredTypeArguments #-}

module VDQ where

sizeOf :: forall a -> Show a => Int
sizeOf = undefined

It produces the error:

VDQ.hs:7:10: error: [GHC-91028]
    • Couldn't match expected type ‘forall a -> Show a => Int’
                  with actual type ‘a0’
      Cannot instantiate unification variable ‘a0’
      with a type involving polytypes: forall a -> Show a => Int
    • In the expression: undefined
      In an equation for ‘sizeOf’: sizeOf = undefined
  |
7 | sizeOf = undefined
  |          ^^^^^^^^^

I think there is room for a lot of improvement. It is easily solvable by turning on Impredicative types.

In my opinion "Turn on ImpredicativeTypes" would be great. Another less good improvement would be to replace "cannot instantiate unification variable with a type involving polytypes" with something else. Because intuitively, if the user is unaware that instantiation variables are just unification variables that GHC keeps track of, in order to avoid implicit instantiation, he would read it and think: "Okay, I know that unification variables stand for monotypes, my code must be wrong then".

GHC version: 9.9.20240105

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