purescript / purescript-typelevel-prelude

Types and kinds for basic type-level programming
BSD 3-Clause "New" or "Revised" License
63 stars 21 forks source link

RowLabels type class and LabelList #9

Closed LiamGoodacre closed 7 years ago

LiamGoodacre commented 7 years ago

A type class RowLabels to compute the list of labels in a closed row. Defined as:

class RowLabels (row :: # Type) (labels :: LabelList) | row -> labels

Where LabelList is defined by:

foreign import kind LabelList
foreign import data Nil :: LabelList
foreign import data Cons :: Symbol -> LabelList -> LabelList
infixr 6 type Cons as :

The labels computed by RowLabels should be sorted and preserve duplicates, e.g:

RowLabels (b :: String, a :: Int, b :: Boolean) ("a" : "b" : "b" : Nil)

With this it is possible to compute a lot more based on rows. We can check if a row has a label, filter labels, rebuild a row with the associated types transformed in some way, perhaps reflect the list as an array of strings.

Any thoughts, ideas, criticism?

LiamGoodacre commented 7 years ago

With this I think we could remove support of closed records from generics-rep deriving 👍 - so that generics-rep only describes data constructors and their positional arguments.

LiamGoodacre commented 7 years ago

This would also let us define Show for records with closed rows.