简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM