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

implement syntax for arity zero vs arity one in uncurried application #139

Merged
merged 2 commits into from
May 25, 2021

Conversation

IwanKaramazow
Copy link
Contributor

Since there is no syntax space for arity zero vs arity one, we parse
fn(. ()) into
fn(. {let __res_unit = (); __res_unit})
when the parsetree is intended for type checking

fn(.) is treated as zero arity application

Fixes #138

@ryyppy
Copy link
Member

ryyppy commented Sep 15, 2020

Not sure if there is any difference, but it might also be worth considering converting it into fn(. ignore())? At least it's easier to understand what's going on, and both versions compile to fn(undefined)

@chenglou
Copy link
Member

Hummmm not too sure

@bobzhang
Copy link
Member

bobzhang commented Jan 4, 2021

@IwanKaramazow the proposal looks good to me.
fn(.) is compiled into fn()
fn(.()) is fn(undefined). For your short-cut implementation, it could be implemented as fn(Pervasives.(()) -- this way you don't need introduce a special name
Edit: a more robust solution: fn(. ()) could be implemented as fn(.{0;()})

@bobzhang
Copy link
Member

bobzhang commented Feb 1, 2021

would my proposal make the implementation a bit more clean? @IwanKaramazow

@IwanKaramazow
Copy link
Contributor Author

@bobzhang not 100%, it results in a type-error: https://rescript-lang.org/try?code=DYUwLgBAZgdhC8EAUA6CB9AlAgfMzA3AFBGyoDeADAUpgL6ZA

It could be changed to: fn(. {ignore(0); ()})

@bobzhang
Copy link
Member

bobzhang commented Feb 3, 2021

@IwanKaramazow it is because we are more strict with sequence types. @ryyppy 's proposal also makes sense, the idea is not to introduce a magic name in the generated code

@ryyppy
Copy link
Member

ryyppy commented Feb 6, 2021

@IwanKaramazow @bobzhang I don't understand how fn(. {ignore(0); ()}) is cleaner than fn(. ignore())? Is there any benefit of having this local scope with two expressions?

I personally use fn(. ignore()) and we also recommend it in the docs right now, so ppl have a reference on how to work around the syntactical limitation. Having fn(. ()) as the more logical equivalent would help reduce unintuitive errors and also helps us keeping the docs lean.

@IwanKaramazow
Copy link
Contributor Author

Yea, let’s go with ignore(). Will finish this tomorrow

@IwanKaramazow IwanKaramazow force-pushed the ArityZeroVsArityOne branch 3 times, most recently from a9ff68c to c63102f Compare February 7, 2021 10:34
@IwanKaramazow
Copy link
Contributor Author

Ok, this PR is now ready to be merged.

The semantics are summarised by the following table:
image
Unfortunately, this is a breaking change. If you look at the table: f(. ()) used to be parsed as f(.) (arity0). With this PR f(. ()) would be parsed as f(. ignore()) (arity1).
@bobzhang do we schedule this for the next breaking changes release?

@bobzhang
Copy link
Member

@IwanKaramazow I am happy to merge it, would you resolve the conflicts?

Iwan added 2 commits May 25, 2021 12:06
Since there is no syntax space for arity zero vs arity one,
we parse
  `fn(. ())` into
  `fn(. {let __res_unit = (); __res_unit})`
  when the parsetree is intended for type checking

`fn(.)` is treated as zero arity application
@IwanKaramazow IwanKaramazow force-pushed the ArityZeroVsArityOne branch from b206460 to d247724 Compare May 25, 2021 10:10
@IwanKaramazow
Copy link
Contributor Author

@bobzhang rebased! Do we merge?

@bobzhang
Copy link
Member

yes!

@IwanKaramazow IwanKaramazow merged commit d8441ff into master May 25, 2021
@IwanKaramazow IwanKaramazow deleted the ArityZeroVsArityOne branch May 25, 2021 10:45
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.

Differentiate between fn(.) and fn(.())
4 participants