【问题标题】:How do languages that support operators as first class citizens abide by order of operations?支持操作员作为一等公民的语言如何遵守操作顺序?
【发布时间】:2020-08-19 12:31:29
【问题描述】:

在诸如 F# 等中缀运算符是“函数”或一等公民的编程语言中,它们如何遵守诸如 2 * 4 + 6(其计算结果为 (2 * 4) + 6)之类的运算顺序?

【问题讨论】:

    标签: functional-programming programming-languages


    【解决方案1】:

    对于 Haskell,您可以 specify the precedence level 和运算符的关联性。 Scala 的优先级基于first character of the operator,关联性基于最后一个字符。不知道F#,不过貌似也是基于the characters used的。

    其他一些语言只允许您重载现有的运算符,而不是创建自己的运算符,因此它们保留了其内置对应项的优先级和关联性。

    【讨论】:

      猜你喜欢
      • 2019-09-04
      • 2021-06-11
      • 1970-01-01
      • 1970-01-01
      • 2017-10-24
      • 1970-01-01
      • 1970-01-01
      • 2016-02-15
      • 2017-08-14
      相关资源
      最近更新 更多