I’m experimenting with HList based typed heterogeneous lists.
I have defined the following:
import Data.HList
data ATag
data BTag
type TagList = ATag :*: BTag :*: HNil
bIndex :: Int
bIndex = hNat2Integral (hFind (undefined :: BTag) (undefined :: TagList))
I was expecting bIndex to have value 1. Instead, I get the following error:
No instances for (HEq BTag ATag b,
HFind' b BTag (HCons BTag HNil) n0)
arising from a use of `hFind'
It seems that GHC (7.4.1) is not able to automatically infer the instance
HEq BTag ATag HFalse
Is there any way to make that happen?
There are several flavors of HList’s labels. You are trying to use your own ‘ATag’ and ‘BTag’ phantoms as labels. The HList flavor you are using expects its ‘HNat’ types as labels: ‘HZero’ and ‘HSucc *’.
You need to import one of the Data.HList.Label1 to Label5 modules. And you will need to choose a TypeEq flavor, and the TypeCast flavor to match the TypeEq flavor:
The above works and give ‘bIndex’ the value 1.