-
Notifications
You must be signed in to change notification settings - Fork 53
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
Require types to start with an uppercase letter #1583
Conversation
For example, `True` counts as the reserved word `true`. However, only `Int`, and not `int`, is a reserved word.
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.
The types look more readable to me 👍
Just to check, uppercase is parsed as a concrete type or fails if it does not exist, right? Apologies if I overlooked a test for it.
|
Btw. I think that if you It could look like: swarm-0.4 format --out=Haskell old_code.sw | swarm-0.5 format --in=Haskell --stdin |
That's true, but (1) that would require adding Edit: actually, the big problem right now is that currently none of these approaches would preserve comments; see #1467 . Edit 2: since I personally would really like a tool to do the type case conversion automatically on all my |
@kostmo I've resurrected this PR. When you get a chance, take a look and let me know what you think. I was going to give |
Co-authored-by: Restyled.io <commits@restyled.io>
This is a followup on top of #1583 which turns `swarm format` into a tool for porting existing Swarm code into the newest syntax, via an extra `--v0.5` argument. In particular, this PR: - Generalizes the parser to take a configuration record, which among other things contains the language version being parsed. - Adds code to allow the parser to parse either the current syntax or one version ago (when types did not start with capital letter) depending on the version in the configuration. - The idea is to have the parser always support the current version and one older version, so we can always upgrade version n to version n+1. - Adds a new flag `--v0.5` to the `format` subcommand which causes the input to be parsed in v0.5 mode. However, the output of `format` will always use the latest syntax. Thus, `swarm format --v0.5` reads code in v0.5 format and prints it in the latest format, so this can be used to automatically port existing `.sw` files. This PR also makes a few minor improvements to pretty-printing.
Closes #1547 , which was caused by misspelled/nonexistent types being interpreted as type variables. In #1550 I proposed one solution to the problem, namely, to stop implicitly quantifying types and require explicit
forall
on any polymorphic type. This PR represents an alternative solution: to keep implicit quantification but require all types to start with an uppercase letter, as in Haskell. I think I like this one better but I'm open to feedback.Specifically, with this PR:
Int
,Cmd
,Unit
, etc.) must start with a capital letterint
let f : Int -> Int = \int. int + 1
is fineThis PR obviously represents a bigger breaking change. Once we merge this we might consider adding an option to
swarm format
to be able to parse old code with lowercase types and then reformat it with uppercase, to aid in porting code.Once this is merged I will also regenerate the wiki pages that mention types.
Closes #1550.