Exponentiation operator precedence

Hi folks,

I just started learning Elm and tried to make a plot for the bell curve: y = exp(-x^2).
Since in all languages I am aware of (Haskell, Python, Ruby, Julia), exponentiation operator has a higher precedence than an unary minus, I expected curvy_thing x = e^(-x^2) to work, but it took me half an hour to find out that in Elm unary minus has a higher precedence and I should’ve written e^(-(x^2)). This behavior is extremely confusing, and I believe it would be great to put a huge red warning in the documentation so nobody can make this mistake again. Also, maybe this behavior can be changed because it is unlikely that someone will need to write (-x)^y.

2 Likes

There’s an open issue about this: https://github.com/elm/compiler/issues/1530

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.