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?
CodePudding user response:
The indexing function for HList
is called hLookupByHNat
.
You cannot simply index an HList
by an Int
because 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 of hLookupByHNat
as a lookup function on HList
. But be aware that dependently-typed programming is not going to be easy, even in languages that actually support them.