Skip to content

SPECIALISE instance pragmas allow nested `forall`s/contexts

GHC rejects nested foralls and contexts in instance declarations, like so:

class C a

instance forall a. forall b. C (Either a b)
Bug.hs:6:20: error:
    Instance head cannot contain nested ‘forall’s or contexts
    In an instance declaration
  |
6 | instance forall a. forall b. C (Either a b)
  |                    ^^^^^^^^^^^^^^^^^^^^^^^^

However, GHC permits nested foralls in SPECIALISE instance pragmas, like in the following example:

instance C (Either a b) where
  {-# SPECIALISE instance forall a. forall b. C (Either a b) #-}

This seems inconsistent. If we reject nested foralls in the former, we should reject them in the latter as well.

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