是否有一个类似于Haskell的$(美元符号)的Scala运算符?

编程入门 行业动态 更新时间:2024-10-24 20:14:06
本文介绍了是否有一个类似于Haskell的$(美元符号)的Scala运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否可以像在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运算符?

本文发布于:2023-11-06 21:21:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564703.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类似于   有一个   符号   运算符   美元

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!