Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Pun record declaration fields when possible. #64

Closed
wants to merge 2 commits into from

Conversation

IwanKaramazow
Copy link
Contributor

type a = string
type b = int

type r = {a, b}

Requested in #47

@cristianoc
Copy link
Contributor

@IwanKaramazow was there something to be careful about for unary records?

@IwanKaramazow
Copy link
Contributor Author

That was in record expressions. Not yet sure how we could tackle that one

@chenglou
Copy link
Member

Let's hold off on this one. Not sure about printing record punning yet

@cknitt
Copy link
Member

cknitt commented Jul 23, 2020

@chenglou What exactly are you unsure about / what are your concerns?

@chenglou
Copy link
Member

cknitt it's possible that we reconsider punning in favor of some other syntax possibilities

@bobzhang
Copy link
Member

If we allow punning in writing, we should do punning in printing,
otherwise we should not allow punning in writing either.

This would create confusion for example, people write code:

type t = { hi, lo}

and formatted as

type t = { hi : hi, lo : lo} 

People will read it that you are against such style, if you are against such style, why not prohibit in the beginning (in the parsing)?.

I am not against/for punning, but we should be consistent here

@cknitt
Copy link
Member

cknitt commented Jul 29, 2020

@chenglou I agree with @bobzhang that we should be consistent here.

Also, I think it would be a mistake to remove punning support because:

  1. It would make code more verbose/less readable.
  2. It was supported in the old Reason parser.
  3. Why support it for named function arguments, but not for record fields?
  4. I thought the idea for Reason syntax was to be familiar to JS developers, and JS supports punning for objects fields, too.

In short, not supporting punning would feel like a regression to me, both compared to the old Reason parser and to JS.

So I am quite curious about what the "other syntax possibilities" are that outweigh these concerns.

@bobzhang
Copy link
Member

@cknitt I digged into a little bit. The proposal is to remove punning in type declarations not in expressions where punning is mostly used. Does it sound good to you?

@cknitt
Copy link
Member

cknitt commented Jul 31, 2020

@bobzhang Thanks for digging! That's good news. I had understood Cheng's comments to mean that he would like to remove punning altogether.

@cknitt I digged into a little bit. The proposal is to remove punning in type declarations not in expressions where punning is mostly used. Does it sound good to you?

@pckilgore
Copy link

I don't mind losing punning on types fields (data fields a different story) but agree with Bob that I would dislike the inconsistency of considering it valid syntax but rewriting it on fmt.

@fhammerschmidt
Copy link
Member

One year later I still would love to have this one back. Code just gets more verbose than in Reason.

@ryyppy
Copy link
Member

ryyppy commented May 2, 2022

@IwanKaramazow I guess the conclusion of this discussion is that we want to keep the record field declarations always explicit. For punning record values, we already merged #480.

So I'd propose to close this for now.

@ryyppy ryyppy closed this May 2, 2022
@cristianoc cristianoc deleted the RecordDeclFieldPunning branch June 1, 2022 23:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants