rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Unified Operator Proposal for int, float, and bigint

Open mununki opened this issue 1 year ago • 1 comments

Background

In the current ReScript design, operators for int and float types are distinct, requiring developers, especially those familiar with JavaScript, to learn and remember separate operators for these types. This distinction not only adds a learning curve for newcomers but also complicates the language's simplicity ethos. As the JavaScript ecosystem evolves and considers wider adoption of BigInt for larger integer operations, this approach might necessitate introducing yet another set of operators, further complicating the situation.

Proposal

I propose a syntax layer adjustment to allow a unified operator set for arithmetic operations across int, float, and potentially BigInt types. The goal is to streamline the developer experience by reducing the cognitive load and making the language more approachable for newcomers without introducing significant changes to the type checker.

Key Points:

  • Unified Operators: Use a single set of arithmetic operators that work intuitively across int, float, and BigInt types, similar to how JavaScript handles arithmetic operations without requiring different operators for different numeric types.
  • Minimal Changes to Type Checker: Keep changes to the type checking logic minimal.
  • Backward Compatibility: Ensure that these changes do not break existing codebases. A phased approach or compiler flags could be considered for a transition period.

mununki avatar Mar 13 '24 05:03 mununki

Discussions: https://github.com/rescript-lang/rescript-compiler/pull/6670#issuecomment-1988132107 https://github.com/rescript-lang/rescript-compiler/pull/6670#issuecomment-1989241263

mununki avatar Mar 13 '24 05:03 mununki

Implemented in #7057

cknitt avatar May 05 '25 08:05 cknitt