Why can't I use the Constraint kind in type family declarations?

Viewed 52

I'm using

{-# LANGUAGE TypeFamilies, DataKinds, ConstraintKinds, ExistentialQuantification #-}

and have typed the following code:

class NoConstraint x where {}
instance forall x. NoConstraint x where {}

type family Classes (c :: [* -> Constraint]) (x :: *) :: Constraint
type instance Classes [] x = NoConstraint x
type instance Classes (h : t) x = (h x, Classes t x)

However, GHC(i) rejects this with:

Not in scope: type constructor or class `Constraint'

It seems to be, however, that this should be completely possible.


Edit: I've now found out that there are also other problems with the above code.
However, this remains a valid question.

1 Answers

The problem is because Constraint is not exported by default from Prelude. You can hoogle Constraint to find where it is:

Try adding the following to your module:

import Data.Kind (Constraint)

It solves the problem for me.

Related