unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.81k stars 271 forks source link

Arithmetic Precedence Is Wrong #3467

Open jackie-scholl opened 2 years ago

jackie-scholl commented 2 years ago

This has been mentioned before, three years ago in a closed issue: https://github.com/unisonweb/unison/pull/896

In Unison, 1+2*3 evaluates to 9. This is mathematically incorrect behavior :( Haskell solves this by allowing infix operators to determine their own precedence. Most languages fix this by hardcoding precedence for the standard operators. If one were deeply opposed to the idea of operator precedence, one might ban the expression 1+2*3, calling it invalid syntax because it mixes operators without parentheses for clarity.

runarorama commented 2 years ago

Unison has no precedence rules for functions as of yet, so (+) and (*) behave like all other binary functions: they associate to the left.

https://www.unison-lang.org/learn/language-reference/syntactic-precedence-operators-prefix-function-application/

Unison will eventually get precedence rules (hopefully soon!). I've opened an issue to track: https://github.com/unisonweb/unison/issues/3468

ceedubs commented 3 weeks ago

@runarorama this is resolved as of #5273, right?