Skip to content
This repository was archived by the owner on Jun 5, 2023. It is now read-only.
This repository was archived by the owner on Jun 5, 2023. It is now read-only.

Add Records To Dotty #8

@odersky

Description

@odersky

This is a rough sketch of a possible design of records for Dotty

Types

A single-field record type is of the form (a: T) where a is an identifier and T is a type. It expands into an instance of a trait Labelled$a[T]. We assume that for every field name a present in a program the following trait will be automatically generated:

trait Labelled$a[+T](val a: T)

A multi-field record type (a_1: T_1, ..., a_n: T_n) is equivalent to the intersection of single-field record types (a_1: T_1) & ... & (a_n: T_n). Since & is commutative, order of fields does not matter.

A row type is a tuple of label/value pairs. Each label is a string literal. Unlike for record types, order of labels does matter in a row type.

The base trait Record is defined as follows:

trait Record { def row: Row }

Here, Row is assumed to be a generic base type of HLists. Record values are instances of Record types that refine the type of row.

Values

A record value is of the form (a_1 = v_1, ..., a_n = v_n). Assuming the values v_i have types T_i this is a shorthand for

new Record with
        Labelled$a_1[T_1](v_1) with ...
        ...
        Labelled$a_n[T_n](v_n) {
   def row = (("a_1", a_1), ..., ("a_n", a_n))
}

TODO: Define equality
TODO: Define how to create a record value from a generic HList representation - on the JDK it seems
we can use Java's Proxy mechanism for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions