支持操作员作为第一 class 公民的语言如何遵守操作顺序?
How do languages that support operators as first class citizens abide by order of operations?
在 F# 等编程语言中,中缀运算符是 'functions' 或第一个 class 公民,它们如何遵守运算顺序,例如 2 * 4 + 6(计算结果为(2 * 4) + 6)?
对于Haskell,您可以specify the precedence level and associativity for an operator. Scala bases the precedence on the first character of the operator, and the associativity on the last character. I don't know F#, but it looks like it is also based on the characters used。
其他一些语言只允许您重载现有运算符,而不能创建您自己的运算符,因此它们保留了其内置运算符的优先级和结合性。
在 F# 等编程语言中,中缀运算符是 'functions' 或第一个 class 公民,它们如何遵守运算顺序,例如 2 * 4 + 6(计算结果为(2 * 4) + 6)?
对于Haskell,您可以specify the precedence level and associativity for an operator. Scala bases the precedence on the first character of the operator, and the associativity on the last character. I don't know F#, but it looks like it is also based on the characters used。
其他一些语言只允许您重载现有运算符,而不能创建您自己的运算符,因此它们保留了其内置运算符的优先级和结合性。