Hacker News new | ask | show | jobs
by daniellehmann 1694 days ago
I don't know Swift, but does this mean there are expressions in Swift where the compiler returns an error, because the expression is ambiguous without additional parentheses?

(My understanding of the article is that it mainly argues for _partial_ precedence, not so much that precedence/associativity can be defined in the program - the latter is also the case in other languages, e.g., Haskell.)

1 comments

Yes:

    precedencegroup MyPrecedence {}
    infix operator +++: MyPrecedence
    func +++ (lhs: Int, rhs: Int) -> Int { lhs + rhs }
    let a = 1 + 2 +++ 3
Error:

    Adjacent operators are in unordered precedence groups 'AdditionPrecedence' and 'MyPrecedence'
Very cool, thanks a lot for the example!