-
Notifications
You must be signed in to change notification settings - Fork 54
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
Implement Labeled Tuples #1235
Conversation
@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? |
b8e1f37
to
3c24406
Compare
3c24406
to
fe24986
Compare
Evaluation should continue around:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- floating point exponential notation isn't working anymore
- see inline comments
@@ -201,6 +213,7 @@ let rec var_mention = (name: string, uexp: Exp.t): bool => { | |||
| BuiltinFun(_) => false | |||
| Cast(d, _, _) => var_mention(name, d) | |||
| Ap(_, u1, u2) | |||
| Dot(u1, u2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check to make sure label positions are not being recursed into for variable mentions / recursive functions / etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cyrus- since we don't have the label sort introduced, the variables in label position are still being evaluated:
I can try to make these indet, but it's not clear to me that it's preferable to stop dynamics for the expression. If we still allow evaluation I think we want to continue to recurse into the "label position" in SyntaxTest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems somewhat related to decisions for now evaluation should proceed in non-empty holes #1497 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've put everything in label position in multiholes if it's not a label.
Labeled Tuples
Overview
This PR introduces labeled tuples to Hazel, allowing tuple elements to be named using the
=
operator.What Are Labeled Tuples?
Labeled tuples allow elements within a tuple to be named using the
=
operator. For example:Here,
x=1
andy=2
define labeled elements. These labels are only relevant within the enclosing tuple. Conceptually,=
acts as a binary operator that pairs a label (a string) with an expression.Labeled Tuple Features
Labeled elements can appear in any order when matched against a labeled tuple type, while unlabeled elements must maintain relative order.
Examples
(x=1, True, y=6)
correctly matches the type(Bool, y=Int, x=Int)
.let x=a, b = (y=2, x=4)
binds4
toa
and2
tob
.Dot Operator/Projection (
.
)The dot operator allows extracting labeled elements from tuples:
Singleton Labeled Tuples
A labeled tuple with a single element, such as
(a=1)
, follows the same principles as multi-element labeled tuples but has some unique characteristics:(a=1)
, but parentheses are optional, soa=1
is also valid.1
against(a=Int)
infers1
asa=1
.(a=1).a
correctly extracts1
.Implementation Strategy
Labeled tuples are implemented by extending existing constructs in expressions, patterns, and types:
TupLabel
: Represents a labeled tuple element in expressions, patterns, and types.Label
: Represents the label itself, always appearing in the label position ofTupLabel
.MultiHole
Dot
: In expressions represents tuple label projection (i.e., field access). The right-hand argument ofDot
must be aLabel
.Automatic label inference
Future work