Is it possible to place inequality constraints on haskell type variables?

后端 未结 4 1236
悲哀的现实
悲哀的现实 2020-12-28 14:51

Is it possible to place an inequality constraint on the typevariables of a function, à la foo :: (a ~ b) => a -> b as in GHC type family docs, except ineq

4条回答
  •  伪装坚强ぢ
    2020-12-28 14:58

    From GHC 7.8.1. closed type families are available. The solution is much simpler with them:

    data True
    data False
    
    type family TypeEqF a b where
      TypeEqF a a = True
      TypeEqF a b = False
    
    type TypeNeq a b = TypeEqF a b ~ False
    

提交回复
热议问题