-
Notifications
You must be signed in to change notification settings - Fork 38
Conversation
What's the reasoning behind this? I'm in general not against this PR, I'm just wondering what your thought process is. |
What's the corresponding behaviour for types? Being consistent there could be positive, all else equal. |
@cristianoc @IwanKaramazow Some history: Reason used to do this for both record values and types, i.e. type a = int;
type b = string;
type c = { a: a, b: b };
let a = 1;
let b = "";
let c = { a: a, b: b }; would reformat to type a = int;
type b = string;
type c = {
a,
b,
};
let a = 1;
let b = "";
let c = {a, b}; ReScript (up to the last release 9.1.4) used to do the inverse - change Current state in ReScript after #480 is that record values are printed exactly the way the user wrote them (whether punned or not), but record types are still expanded. The latter is because Cheng and Bob stated in #64 (comment) and #64 (comment) that they didn't want punning for record type declarations. I do not care that much about the type declarations, but I strongly favor the punned version for record values. It is nice that, since #480, the printer is leaving the punned version untouched, but I would prefer if the punned version was actually enforced by the printer to ensure a consistent and more readable style in ReScript codebases. |
It seems for each combination one could come up with some argument. Can't see compelling reasons either way. |
Wondering how relevant the question for types is. Most often the names would be different. |
@cknitt any thoughts on how to progress this? Perhaps more feedback from the forum? |
Yes, will ask on the forum later today. 👍 |
One thought is that for the type counterparts, punning might be pretty confusing: type coordinate = {x, y: int} One could argue that some people will interpret |
Remember that discussion. Yes symmetry between types and values does not seem like a good idea. |
Looks like this can be merged, based on discussions in the forum. |
Leaving a link to the discussion: https://forum.rescript-lang.org/t/printing-punned-record-fields/3447 |
I have added test cases for single-element records (which cannot be punned). I will now close the discussion and merge the PR. |
In #480, I already prevented the printer from expanding
{a, b} to {a: a, b: b}
.At the time, I refrained from making it collapse
{a: a, b: b}
to{a, b}
like it used to be the case in Reason.But I think it would actually be the better behavior to always print record fields as punned when possible.
Now that the next release is going to be a major version (10.0), it would IMHO be fine to make that change.