Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating methods for accessing fields of records #23

Closed
ppolesiuk opened this issue Mar 27, 2024 · 0 comments · Fixed by #94
Closed

Generating methods for accessing fields of records #23

ppolesiuk opened this issue Mar 27, 2024 · 0 comments · Fixed by #94
Assignees
Labels
enhancement New feature or request

Comments

@ppolesiuk
Copy link
Member

For record-like types, e.g.,

data Vec X = Vec { x : X, y : X }

we could automatically generate methods for accessing fields of these types. In this example it would be

method x {self = Vec { x }} = x
method y {self = Vec { y }} = y

There are some design decisions that should be made. First of all, when should we generate such methods? The possible options I see are the following (I prefer option 2 or 4).

  1. Always, for ADT with single constructor (with some limitation related to existential types: see below).
  2. For types explicitly marked as records (e.g., by a special keyword, or when the constructor name is omitted or the same as the name of type).
  3. For each field that is shared between all constructors.
  4. By explicitly marking the fields, e.g., by something like deriving in Haskell.

Moreover, for types that stores existential types, e.g.,

data T = T { X, a : X, b : Int }

it is not possible to generate some methods (method a in this example, but method b is still reasonable). If we follow option 2, then we should forbid existential types in records, or omit some automatically generated methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants