What do you really want
data HKList :: (k -> *) -> [k] -> * where Nil :: HKList f '[] (:*) :: fx -> HKList f xs -> HKList f (x ': xs)
What you can use as a regular heterogeneous list
type HList = HKList Identity
Or with additional information about some constant type e attached to each value (or other interesting functors)
HKList ((,) e)
Or with additional information recorded in the dictionary
data Has ca where Has :: ca => a -> Has ca type ConstrainedList c = HKList (Has c)
Or save lists of only fixed restrictions
data Dict1 :: (k -> Constraint) -> k -> * where Dict1 :: ck => Dict1 ck
What can you use to determine the idea of ββan entire list of types that satisfy the constraint
class All c xs where dicts :: HKList (Dict1 c) xs instance All c '[] where dicts = Nil instance (All c xs, cx) => All c (x ': xs) where dicts = Dict1 :* dicts
Or anything else you can do with good k -> *
You can freely convert between working with All c xs => HList xs and HKList (Has c) xs
zipHKList :: (forall k. fk -> gk -> hk) -> HKList f xs -> HKList g xs -> HKList h xs zipHKList _ Nil Nil = Nil zipHKList f (x :* xs) (y :* ys) = fxy :* zipHKList f xs ys allToHas :: All c xs => HKList Identity xs -> HKList (Has c) xs allToHas xs = zipHKList f dicts xs where f :: Dict1 ck -> Identity k -> Has ck f Dict1 (Identity x) = Has x hasToAll :: HKList (Has c) xs -> Dict (All c xs) hasToAll Nil = Dict hasToAll (Has x :* xs) = case hasToAll xs of Dict -> Dict
full code
I wrote this several times earlier for various projects, but I did not know that it was in the library anywhere until Cosmicus indicated that it was in generics-sop .
source share