Question: Exponentiation precedence

In JS, exponentiation operator is right-associative: a ** b ** c is equal to a ** (b ** c) .

In ReScript is left-associative:

Example:

let a = 2. ** 3. ** 2.

Compile to:

var a = Math.pow(Math.pow(2, 3), 2);

Result: 64

Node:

> 2 ** 3 ** 2
> 512

Is this the expected behavior?

Why not compile to Math.pow(2, Math.pow(3, 2))?

I think binary operators are parsed as left-associative. E.g. 1-4-5.
Not sure if intentional for exponentiation.

Seems like a bug. It should be right associative - along with the negate operator

I.e. 2. ** -3. ** 2 should be Math.pow(2, -Math.pow(3, 2))

In v11 the operator ** will be right-associative.

2 Likes