SCL: operator precedence
|Assignee:||Hannu Niemistö||% Done:|
|Release notes:||SCL default operator precedence changed to 9 as in Haskell so `foo` binds tighter than $, where foo is a binary function.|
|Velocity based estimate||-|
|Release||Simantics 1.18.1||Release relationship||Auto|
Try this on the SCL console:
foo x y = x + y (0-) $ 3 `foo` 4
Surprisingly the result is 1: apparently $ binds tighter than `foo`. This is different from Haskell, where the result would be -7.
(refs #5568) Quick workaround to precedence handling bug introduced in the previous commit to this issue.
#2 Updated by Hannu Niemistö over 3 years ago
- Status changed from New to Resolved
I fixed the default preference to 9 as in Haskell. However, contrary to Haskell the default assosiativity of operators is still non-assosiative:
> 1 `foo` 2 `foo` 3 ^^^^^ (1:12-1:17) Operator foo is not associative.
After the modification:
> foo x y = x + y > (0-) $ 3 `foo` 4 -7
I also added support for using variables (not defined on top level) as operators:
> g f x = x `f` x > g (+) 3 6