简体   繁体   中英

Equality on constraints

Basically, given {-# LANGUAGE PolymorphicKinds, ConstraintKinds, TypeFamilies #-} (and more, if necessary), does the (~) type-level operator work on type-level expressions of kind Constraint ? I tried googling the answer, but had no luck.

Yes, it is possible. Because types of kind Constraint are finite sets of atomic type constraints, you can test their equality very easily.

The PolyKinds extension is not necessary, however. Also, there's very few situations when this kind equality would actually be useful, because I don't see a practical way of passing polymorphic constraints as the arguments c1 , c2 to Bla , so the constraint equality would be a tautology in every case ( Show ~ Show here):

{-# LANGUAGE ConstraintKinds, TypeFamilies #-}

type Bla c1 c2 a = (c1 a, c2 a, c1 ~ c2)

foo :: Bla Show Show a => a -> IO ()
foo = print

main = foo "Bla"

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