Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Ambiguity when integrated with partial application #3

Closed
JLHwung opened this issue Mar 23, 2021 · 2 comments
Closed

Ambiguity when integrated with partial application #3

JLHwung opened this issue Mar 23, 2021 · 2 comments
Assignees

Comments

@JLHwung
Copy link

JLHwung commented Mar 23, 2021

Since partial application also uses ?, it is unclear what the example

0
|> f(?, ?)
|> ?(1)

should be desugared into. Specifically there are three potential interpretations:

f(0, 1)

where the first ? is topic reference, the second ? is placeholder.

f(1, 0)

where the second ? is topic reference, the first ? is placeholder

f(0, 0)(1)

where both ? is topic reference.

@js-choi
Copy link
Collaborator

js-choi commented Apr 2, 2021

Thanks for the comment. Yes, it’s true: if ? is chosen as the topic reference’s token, then it becomes ambiguous with the current proposal for partial-function-application (PFA).

In fact, Hack pipes and the current PFA proposal also conflict with each other on a conceptual level. Both proposals address a similar problem—piping values into placeholders—in different ways. The current PFA proposal is built to integrate with F# pipes, rather than Hack pipes, in certain situations.

Hack pipes Current PFA (with F# pipes)
x |> ? + 1 x |> y=> y + 1
x |> f(?, 0) x |> f(?, 0)
a.map(x=> x + 1) a.map(x => x + 1)
a.map(x=> f(x, 0)) a.map(f(?, 0))
a.sort((x,y)=> x - y) a.sort((x,y)=> x - y)
a.sort((x,y)=> f(x, y, 0)) a.sort(f(?, ?, 0))

There are two possible solutions, which are not mutually exclusive:

  1. The PFA proposal could adopt Hack-pipe topic references. This option is already described in the “pipe functions” section of the Hack-pipes explainer. Essentially, a +> prefix operator would create a function that binds its arguments to Hack-style topic references ?0 (same as ?), ?1, ?2, …. This would make the PFA proposal more flexible – able to handle partially applying any expression, not only function calls:

    Hack pipe functions Current PFA
    a.map(+> ? + 1) a.map(x => x + 1)
    a.map(+> f(?, 0)) a.map(f(?, 0))
    a.sort(+> ?0 - ?1) a.sort((x,y)=> x - y)
    a.sort(+> f(?0, ?1, 0)) a.sort(f(?, ?, 0))
  2. The Hack-pipes proposal could switch the topic reference’s token from ? to another token, like %, @, or #. We changed the token from # to ? only a few weeks ago, in an effort to make Hack pipes more palatable to some TC39 members, and we’ve been delaying serious bikeshedding of the particular token to the future (see Bikeshedding the Hack topic token proposal-pipeline-operator#91 (comment)). We might decide against ? for other reasons anyway (see ?. required to be one and two tokens #2).

Currently the plan is to have the Babel plugin support choosing which token to use as a plugin option, to allow experimentation with different topic-reference tokens like %, @, or #. When any token other than ? is used, there is no syntactic conflict with the current PFA proposal. If we end up implementing ? as an option, then we would have to also forbid combining it with the current PFA proposal’s plugin.

I’ll clarify this relationship between Hack pipes and PFA in the explainer later.

@js-choi
Copy link
Collaborator

js-choi commented May 30, 2021

Resolved in cca63fd. We likely won’t consider ? as a candidate topic token due to #2.

@js-choi js-choi closed this as completed May 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants