Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vinyl: compose record type aliases

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?

like image 618
Impredicative Avatar asked Jan 10 '14 11:01

Impredicative


People also ask

Is it called records or vinyl?

“Record” remains the standard term to describe both shellac and vinyl formats. It's fair to say that while all vinyl albums are records, not every record is a vinyl album. There are different types of vinyl records with various storage capacities and playback speeds, but they all fall under the “record”umbrella.

What is a shellac record?

Shellacs or 78s, also called coarse groove gramophone discs, were the main mass produced audio format of the first half of the 20th century. The shellac discs were pressed from a wax matrix that was made during a professional recording.

What are the little records called?

Single discs are physically smaller – usually 7 inch 45 RPM releases. If you purchased the full length, 12-inch album, you have an LP. If you purchase that 7-inch single, you have an EP.


1 Answers

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
like image 94
Impredicative Avatar answered Oct 17 '22 18:10

Impredicative