I'm using HList package and I need two functions like (!!) and elem. The first function receives an HList and an integer n and returns the n-th element of the HList. The second one receives an HList and an element and verify if that element is in the HList based on the Eq instance of that element.
Can someone help me achieve this?
The indexing function for
HListis calledhLookupByHNat.You cannot simply index an
HListby anIntbecause the type of the result depends on the index, and Haskell does not have dependent types (yet). It is possible to emulate dependent types in Haskell, hence the existence ofhLookupByHNatas a lookup function onHList. But be aware that dependently-typed programming is not going to be easy, even in languages that actually support them.