You can use the HSet property for the HList from HList package:
{-# LANGUAGE FlexibleInstances #-} import Data.HList class (HList l, HSet l) => ThisIsSet l where -- Here we have @ l@ which is @ HList@ _and_ @ HSet@. test :: l -- This is ok: instance ThisIsSet HNil where test = hNil -- And this: instance ThisIsSet (HCons HZero HNil) where test = hCons hZero hNil -- And this (HZero != HSucc HZero): instance ThisIsSet (HCons HZero (HCons (HSucc HZero) HNil)) where test = hCons hZero (hCons (hSucc hZero) hNil) -- This is an error since HSucc HZero == HSucc HZero: instance ThisIsSet (HCons (HSucc HZero) (HCons (HSucc HZero) HNil)) where test = hCons (hSucc hZero) (hCons (hSucc hZero) hNil)
to work with other types you need to write HEq for them.
source share