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

Implement Labeled Tuples #1235

Draft
wants to merge 90 commits into
base: dev
Choose a base branch
from
Draft

Implement Labeled Tuples #1235

wants to merge 90 commits into from

Conversation

WondAli
Copy link
Contributor

@WondAli WondAli commented Mar 5, 2024

Goal: Implement Labeled Tuple functionality into Hazel.
Note: I don't think I can change the source branch on the old pull request. This redesign of the implementation was started on a new branch, so the old pull request (and branch) is outdated.

TODO: Add more detail to the pull request; add more detail about syntax and semantics

What are Labeled Tuples?
An element in a tuple can be "labeled" or "named" with the = operator. For example, (x=1, y=2) is a tuple expression in which its elements are labeled x and y respectively. These labels are relevant only within their nearest enclosing tuple.
The = operator can be thought of as a binary operator that takes in a string and an expression, and returns the expression.

(Uncertain) A labeled element is type-consistent with the type of the element it is labeling.

Labeled Tuple Features
When analyzed against a labeled tuple type, the labeled items can be placed anywhere in the tuple expression and tuple type (the unlabeled items must be in relative order to each other).

  • Ex: (x=1, True, y=6) is properly typed against (Bool, y=Int, x=Int)
  • Ex: Let x=a, b = (y=2, x=4) will bind 4 to a and 2 to b

Dot Operators
The dot operator . can be applied to a tuple to extract a labeled element.
For example, (x=1, 2, 3).x is equivalent to 1
Currently undefined for anything except tuple expressions.

Implementation Strategy

  1. Implement a "label" term to express the labeled tuple element.
  2. Modify tuple semantics to consider labeled term contained within the tuple.
  3. Implement the dot operator as a new expression that takes an expression and a pattern (var only)
  4. Modify labeled tuple semantic interactions with let-binding, casting, function application, etc.

Checkpoints:

  • finish writing the draft pull request
  • Implement the Label term that simply wraps an element with a string.
  • Tuples type-check assuming all elements are in order.
  • Tuples type-check considering rearrangements of labeled elements.
  • Tuple type-checking when there is an unequal number of labeled elements
  • Dot operation on Tuple expressions
  • Labeled tuples as function arguments
  • Code Cleaning and Optimization
  • Add documentation buffer for labeled tuples
    Known Bugs:
  • Label uniqueness in a tuple needs to be checked during statics (currently dynamic check is broken too?)

@WondAli WondAli added the in-development for PRs that remain in development label Mar 5, 2024
@WondAli WondAli self-assigned this Mar 5, 2024
@WondAli WondAli mentioned this pull request Mar 5, 2024
@cyrus-
Copy link
Member

cyrus- commented May 1, 2024

@WondAli playing with this branch, looks like the labels aren't showing up in the types of the tuples (and so you get weird run-time errors when projecting out a label that doesn't exist). is there a specific issue with adding labels to product types?

@WondAli WondAli force-pushed the labeled-tuple-rewrite branch 2 times, most recently from b8e1f37 to 3c24406 Compare August 24, 2024 21:16
@7h3kk1d
Copy link
Contributor

7h3kk1d commented Oct 14, 2024

TODO test nested dot operators

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in-development for PRs that remain in development
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants