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.
The
generics-soppackage offers this out of the box.A heterogeneous list can be defined in
generics-sopby usingand instantiating it to the identity type constructor
I(fromgenerics-sop) orIdentity(fromData.Functor.Identity).The library then offers the constraint
Allsuch that e.g.is the type of a heterogeneous list where all contained types are in the
Showclass. Conceptually,Allis a type family that computes the constraint for every element in a type-level list:(Only that in the actual definition,
Allis additionally wrapped in a type class so that it can be partially applied.)The library furthermore offers all sorts of functions that traverse and transform
NPs given a common constraint.