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

Natural / Integer syntax suggestion #138

Closed
sellout opened this issue Apr 30, 2018 · 10 comments
Closed

Natural / Integer syntax suggestion #138

sellout opened this issue Apr 30, 2018 · 10 comments

Comments

@sellout
Copy link
Collaborator

sellout commented Apr 30, 2018

tl;dr: Change the grammar to move the + sigil to Integers and Doubles, like

Natural <- [0-9]+
Integer <- [+-] [0-9]+
Double <- [+-] [0-9]* '.' [0-9]+

I have a few justifications for this:

  • personal: Using Dhall at work, we tend to mostly use Natural, with Integer and Double being extremely rare (I find this true of coding in Haskell, as well – it’s mostly the lack of availability of Naturals that makes it not the case in other languages, IMO, although I know it does also depend on the domains that one works in)
  • mnemonics: “signed” vs “unsigned” numbers, also “natural” in the sense of “unadorned”
  • syntax: Since Natural is the only numeric type with operations, so +2 + +3 is, to me, much harder to read than 2 + 3
  • cardinality(?): I think encouraging smaller types is good practice, and simpler syntax for Naturals than Integers should help with that

I know it’s also a significant breaking change across like every config file ever, so …

@Gabriella439
Copy link
Contributor

Yeah, it's a pretty breaking change, but I still think it's a good idea and I agree with all the points you made. I think it's mainly a matter of giving this issue more visibility so that people can chime in about whether or not they think the disruption is worth the benefit. I'll try to broadcast this more widely.

@joneshf
Copy link
Collaborator

joneshf commented Apr 30, 2018

I 100% support this!

@KirinDave
Copy link

I think the cleanup to arithmetic is worth it.

@vmchale
Copy link

vmchale commented Apr 30, 2018

@sellout I would note that the cardinality is the same in either case.

@sellout
Copy link
Collaborator Author

sellout commented Apr 30, 2018

@vmchale Yeah, that‘s why I added the “(?)” 😄 I just didn’t have a better term for it.

@Gabriella439
Copy link
Contributor

Gabriella439 commented Apr 30, 2018

Also, this would probably also change the behavior of Natural/show and Integer/show, which would be a good thing, since most people want to render Natural numbers directly to unsigned numbers (i.e. just use Natural/show n instead of Integer/show (Natural/toInteger n))

One consequence of this would be that there would be no way to render a positive Integer as an unsigned number, but I think that's an acceptable loss

@evincarofautumn
Copy link

Sounds like a good idea. A small conversion utility might be helpful for upgrading. I dunno how many users Dhall has at the moment, but it’s a very new language, and IMO people should expect some breaking changes while the core language is being figured out.

@f-f
Copy link
Member

f-f commented May 1, 2018

I totally agree with all of this thread 👍

@Gabriella439
Copy link
Contributor

Seems like unanimous agreement to me. If nobody objects by tomorrow then we should proceed with a pull request to change the semantics.

@sellout: Did you want to submit the pull request? If not, I can do so

Gabriella439 added a commit that referenced this issue May 3, 2018
Fixes #138

This changes the grammar for `Natural` numbers to no longer require a
leading `+` and changes the grammar for `Integer`s to require a leading
`+` for non-negative `Integer`s.

This also makes a matching change to `Integer/show` and `Natural/show`
to reflect the changes to the grammar since they must generate valid
Dhall code
@Gabriella439
Copy link
Contributor

I put up a pull request with the proposed change to the grammar and semantics in #141

Gabriella439 added a commit that referenced this issue May 7, 2018
Fixes #138

This changes the grammar for `Natural` numbers to no longer require a
leading `+` and changes the grammar for `Integer`s to require a leading
`+` for non-negative `Integer`s.

This also makes a matching change to `Integer/show` and `Natural/show`
to reflect the changes to the grammar since they must generate valid
Dhall code
philandstuff added a commit to philandstuff/dhall-lang that referenced this issue Feb 8, 2019
The parser tests had a number of cases where they had Natural and
Integer syntax swapped round.  This presumably dates from before dhall-lang#138
switched the grammar of Integer and Natural.

Note that this difference doesn't actually matter for these parsing
tests, because an expression like `+1 : Natural` still parses correctly,
it just fails to typecheck.  But I found it confusing to have the syntax
so consistently backwards in the tests, so I thought it was worth
changing.
Gabriella439 pushed a commit that referenced this issue Feb 9, 2019
The parser tests had a number of cases where they had Natural and
Integer syntax swapped round.  This presumably dates from before #138
switched the grammar of Integer and Natural.

Note that this difference doesn't actually matter for these parsing
tests, because an expression like `+1 : Natural` still parses correctly,
it just fails to typecheck.  But I found it confusing to have the syntax
so consistently backwards in the tests, so I thought it was worth
changing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants