Why are additional type variables not allowed in class constraints?

Consider this little useless example:

{-# LANGUAGE TypeFamilies #-}

f :: (b ~ [a], Show b) => a -> Int
f _ = 0

      

With the extension, FlexibleContexts

you can replace the context with an f

equivalent but more readable one:

f :: Show [a] => a -> Int

      

Now consider the same parameter only with a class instead of a function:

{-# LANGUAGE TypeFamilies, FlexibleContexts #-}

class Show [a] => F a

      

If I try to replace the context f

with an equivalent but less readable

class (b ~ [a], Show b) => F a

      

then I get Not in scope: type variable ‘b’

from GHC.

Why is it not possible to use an additional type variable in the class context?
What is the reason for this limitation?

+3


source to share





All Articles