rescript-lang / rescript-compiler

The compiler for ReScript.
https://rescript-lang.org
Other
6.74k stars 448 forks source link

External bindings use currying when the signature is not inlined #7002

Open JonoPrest opened 2 months ago

JonoPrest commented 2 months ago

See playground:

https://rescript-lang.org/try?version=v11.1.3&code=AIWw9gJgrgNgpgCgEQgJ4FoCWA7ALumTAIyQEoACOAD1zgCdsBDGcxiCALnIR1wBpyvCgF4AfILzlh5JGwhIAUAtyoADnAm4A8qqndeAoVPG8FoSLEQoMvAsTKUa9JiwDOUIl1469SdySV4XFZ2AEY9RmNWdFE5BFDSBSDyf3DpSLFo0X94xKA

@module("my-int-lib") external add: (int, int) => int = "add"

type intOp = (int, int) => int
@module("my-int-lib") external sub: intOp = "sub"

let add1 = a => a->add(1)
let sub1 = a => a->sub(1)

compiles to:

// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Curry from "./stdlib/curry.js";
import * as MyIntLib from "my-int-lib";

function add1(a) {
  return MyIntLib.add(a, 1);
}

function sub1(a) {
  return Curry._2(MyIntLib.sub, a, 1);
}

export {
  add1 ,
  sub1 ,
}
/* my-int-lib Not a pure module */

Where add1 is applied without currying and sub1 is applied with currying and the only difference is passing a signature vs inlining it.

cknitt commented 1 month ago

This issue was already solved in v12 (in the process of removing curried mode).

The question is if we want to provide a fix for v11, too.