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
haskell


source to share


No one has answered this question yet

See similar questions:

15
Is it possible to introduce additional type variables to the superclass constraint?

or similar:

534
Large-scale design in Haskell?
218
Why does Haskell (GHC) bark so fast?
209
When is -XAllowAmbiguousTypes suitable?
15
How to set constraints on a variable of type `Constraint`?
4
GHC Extension Semantics Allowing Method Constraints (-XConstrainedClassMethods)
2
Avoiding error by using mutually recursive default methods in class classes
2
GHC: why does type ambiguity disappear when using let
1
The problem is to explicitly specify the type using a type variable
1
Why is a variable of this type ambiguous when it should be in scope?
1
Reducing Satisfied Constraints for Common Types



All Articles
Loading...
X
Show
Funny
Dev
Pics