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

passing unit to uncurried function #3429

Closed
jey opened this issue Mar 21, 2019 · 3 comments
Closed

passing unit to uncurried function #3429

jey opened this issue Mar 21, 2019 · 3 comments

Comments

@jey
Copy link

jey commented Mar 21, 2019

I seem to be hitting an edge case when trying to pass unit to an uncurried function. My intention is to create a Js.Promise.t(unit) representing the completion of a side-effect.

let x: Js.Promise.t(unit) =
  Js.Promise.make((~resolve, ~reject) => {
    /* causes compile error:
     *
     *    Found uncurried application [@bs] with arity 1, where arity 0 was expected.
     *    This has type: `(. unit) => unit`, but somewhere wanted `(. unit) => 'a`
     *
     * and gets turned into `resolve(.)` by refmt
     */
    //resolve(. ());

    /* works as expected
     */
    let nil = ();
    resolve(. nil);

    /* mysteriously works. maybe because "zero-arity" functions don't exist,
     * they are actually unary functions taking unit, so `ignore` has inferred
     * type `unit => unit`
     */
    resolve(. ignore());

    /* but then why not this? perhaps because the above only applies when currying.
     */
    //resolve(.);
  });
@bobzhang
Copy link
Member

since in ocaml, there is no function which has arity zero, so that fn (.) is taken as a special form that fn is supposed to have zero arity.
In this case, reason could be improved to differentiate between resolve(. ()) and resolve(.), I will ask

@bobzhang
Copy link
Member

@jey I created such issue in reason repo, you can comment it there.

@ryyppy
Copy link
Member

ryyppy commented Jan 3, 2021

The latest solution to this problem is implemented in a draft PR within the rescript syntax repo.

The code needs to expand into some more code, so it's not clear yet if this is the best solution.

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

3 participants