是否可以像在Haskell中使用$强制在Scala中强制运算符优先级?
Is there any way to force operator precedence in Scala like you do in Haskell with $?
例如,在Haskell中,您拥有:
For example, in Haskell, you have:
a b c = ((a b) c)和
a $ b c = a (b c)在Scala中有类似的方法吗?我知道Scala本身没有运算符,但是有没有办法实现类似的效果?
Is there a similar way to do this in Scala? I know Scala doesn't have operators per se, but is there a way to achieve a similar effect?
推荐答案中缀vs.符号通常以类似的方式用于控制优先级:
infix vs . notation is often used in a similar fashion to control precedence:
a b c d == a.b(c).d a.b c d == a.b.c(d) a b c.d == a.b(c.d)Scala对于固定符号中使用的运算符也有固定的优先顺序:
Scala also has a fixed precedence ordering for operators used in infix notation:
(all letters) | ^ & < > = ! : + - * / % (all other special characters)通常可以显式选择名称以利用此优势.例如,标准解析器库中的~和^^.
Names can usually chosen explicitly to take advantage of this. For example, ~ and ^^ in the standard parsers library.
更多推荐
是否有一个类似于Haskell的$(美元符号)的Scala运算符?
发布评论