Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 842
schuelermine Avatar asked Sep 21 '25 02:09

schuelermine


1 Answers

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

  • https://hoogle.haskell.org/?hoogle=Constraint

Try adding the following to your module:

import Data.Kind (Constraint)

It solves the problem for me.

like image 76
Shersh Avatar answered Sep 23 '25 02:09

Shersh