Equality on constraints

守給你的承諾、 提交于 2020-01-24 02:55:27

问题


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.


回答1:


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"


来源:https://stackoverflow.com/questions/9622840/equality-on-constraints

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!