Skip to content

passing unit to uncurried function #3429

Closed
@jey

Description

@jey

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(.);
  });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions