-
Notifications
You must be signed in to change notification settings - Fork 57
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
Handling of record field names is inconsistent: different for record creation and record update #2968
Comments
In general, maybe we should re-think how we handle local recursive definitions and invent some rules that align with actual use-cases but are still not too complex to be confusing. Because when someone writes e.g.,
they don't want I think it's quite annoying and confusing that we treat zero-argument function definitions as recursive by default. Maybe a general exception is reasonable here? But then we need some way of indicating that we want a recursive definition. In an eager language this is extremely rare for zero-argument definitions, but one could want something like:
I think all zero-argument recursive definitions need the |
I propose the following general rule. A definition is treated as recursive only if one of the following holds:
Otherwise, the definition is not recursive. We treat all definitions this way (top-level, let, record creation/update). I think this aligns quite closely with actual use-cases and is not too complex to be obscure. In a Perhaps we might even do without the
|
This is super-confusing: the inconsistency is also with record puns. The expression
is equivalent to
The expression
is equivalent to
In the first expression, the |
Summary of what we briefly discussed online
|
Idea: should we use |
We agreed to not have a special syntax to refer to the old value, for now. |
* Closes #2968 * Implements detection of function-like definitions, which either: - have some arguments on the left of `:`, or - have at least one clause. * Only function-like definitions are recursive. * Non-recursive definitions are not mutually recursive either, and can be used only after their definition. This necessitates rearranging some definitions in existing Juvix code. * Changes the scoping of identifiers in record updates. Now field names on the right side don't refer to the old values of the record fields but to identifiers in scope defined outside the record update. To refer to old values, one needs to explicitly use record projections, e.g. ``` r@Rec{x := Rec.x r} ```
* Closes #2968 * Implements detection of function-like definitions, which either: - have some arguments on the left of `:`, or - have at least one clause. * Only function-like definitions are recursive. * Non-recursive definitions are not mutually recursive either, and can be used only after their definition. This necessitates rearranging some definitions in existing Juvix code. * Changes the scoping of identifiers in record updates. Now field names on the right side don't refer to the old values of the record fields but to identifiers in scope defined outside the record update. To refer to old values, one needs to explicitly use record projections, e.g. ``` r@Rec{x := Rec.x r} ```
* Closes #2968 * Implements detection of function-like definitions, which either: - have some arguments on the left of `:`, or - have at least one clause. * Only function-like definitions are recursive. * Non-recursive definitions are not mutually recursive either, and can be used only after their definition. This necessitates rearranging some definitions in existing Juvix code. * Changes the scoping of identifiers in record updates. Now field names on the right side don't refer to the old values of the record fields but to identifiers in scope defined outside the record update. To refer to old values, one needs to explicitly use record projections, e.g. ``` r@Rec{x := Rec.x r} ```
In record creation, e.g.,
the
r1
on the right side refers recursively to the field being defined.In record update, e.g.,
the
r1
on the right side refers to ther1
defined by thelet
.Complete example:
This type-checks and prints
B
.We should somehow unify the behaviour.
Possible solutions
rec
keyword or something like this.Option 1 seems to make the language most "unified" (the syntax for definitions is everywhere the same), but also most annoying to use the record update/creation.
Options 2, 3 make the syntax less consistent than 1, but seem to align more closely with actual use-cases.
Any more options?
The text was updated successfully, but these errors were encountered: