I searched Hackage and couldn't find anything like the following but it seems to be fairly simple and useful. Is there a library that contains sort of data type?
data HList c where
(:-) :: c a => a -> HList c
Nil :: HList c
All the HLists I found could have any type, and weren't constrained.
If there isn't I'll upload my own.
I'm not sure this data type is useful...
If you really want
ato be existentially qualified, I think you should use regular lists. The more interesting data type here would beExists, although I'm certain there are variants of it all overpackageHackage already:Then, your
HList cis isomorphic to[Exists c]and you can still use all of the usual list based functions.On the other hand, if you don't necessarily want
ain the(:-) :: c a => a -> HList cto be existentially qualified (having it as such sort of defies the point of theHList), you should instead define the following:Then, if you want to require that all entries of the
HListsatisfyc, you can make a type class to witness the injection fromHList asinto[Exists c]whose instance resolution only works if all the types in theHListsatisfy the constraint: