Vinyl: compose record type aliases

haskell, type-level-computation, vinyl

Solution

Turns out there's a very easy answer to this which I managed to miss:

`Data.Vinyl.Rec` defines both cons and append for type level lists, so the following works:

type MeasuredPerson = ("height" ::: Int) ': Person

If I had two lists, I could append them as follows:

type Other = Person ++ Address

Problem

In Vinyl, I can define a type alias for a record to make it easier to export to other modules: ``` import Data.Vinyl name = Field :: "name" ::: String age = Field :: "age" ::: Int type Person = ["name" ::: String, "age" ::: Int] ``` Now suppose I add another field storing height. ``` height = Field :: "height" ::: Int ``` I would like to nicely construct a type alias for the record containing a `Person` and `height`. Naively, that might look something like this: ``` type MeasuredPerson = ("height" ::: Int) : Person ``` This syntax doesn't work, obviously! Is there a way to do this? Are there any good references that explain the type-level array syntax that seems to be in use here?

Original source