Quantified predicate must have a class or type variable head [GHC-02550]
Quantified constraints
are constraints which have their own constraints. The
head of a quantified constraint is the constraint on the right side of the
=>
operator. For example, the head of the quantified constraint Ord a => Eq a
is Eq a
. This error message states that the head of a quantified constraint
must not be a constraint resulting from, for example, a type family; it must
be either a class constraint or a type variable.
Examples
Bad quantified constraint in function type
In this example, a quantified constraint occurs in the type of a binding. Because the head of the quantified constraint is computed from a type family, we get the following error message:
• Quantified predicate must have a class or type variable head:
a => A a
• In the quantified constraint ‘a => A a’
In the type signature: f :: (a => A a) => ()
One potential fix for this is to convert the type family into a class.
QuantifiedFunction.hs
Before
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE TypeFamilies #-}
module QuantifiedFunction where
import Data.Kind
class C a where
type family A :: k -> Constraint
f :: (C Int => A Int) => ()
f = ()
After
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE TypeFamilies #-}
module QuantifiedFunction where
import Data.Kind
class C a where
class A a where
f :: (C Int => A Int) => ()
f = ()