Type-Level Heterogeneous List

2017-06-20
haskelltype-level

HList is a well designed package for type level heterogeneous lists. We will take a look at the main declaration to get more familiar with type level programmin in Haskell.

Promote data types to to kind level. We want to use [] at the type level to operate over a list of types that we use to calculate the type signature.

Allow multiparameter typeclass instances instance C (Either a String) where ....

Allow typeclass instances for nested types instance C (Maybe Int) where ....

Allow deriving instance separated from the type declaration. It can be in the same file or another file.

Allow indexed and data type families. The instances of data families can be data types and newtypes.

Allow the use and definition of types with operator names.

HList is a list of inhabited types. They must be of kind *. HNil is an empty list of types. HCons is a constructor to concatentate to types.

With deriving instance, Eq and Ord are straightforward.

Finally, we can iterate over the types to create an instance of Show and run a simple example.

References