English 中文(简体)
Scala语自由风格的案例
原标题:The case for point free style in Scala

这一点在菲律宾工人党的表象上似乎确实是显而易见的,但是在Schala,什么是自由的风格? 真正出售我关于这个专题的事例表明,在某种方面(例如绩效、权宜、可维持性)自由风格比解决非点自由风格的同一问题更为明显。

最佳回答

简言之,它想避免在不需要名字的地方指定一个名字,而是考虑一个三边的例子:

List("a","b","c") foreach println

在此情况下,foreach正在寻求接受。 String => Unit , 这是一项接受“强力和回报股”的职能(基本上,没有可观的回报,而且完全通过副作用运作)

无需将名字贴上每一条星号,然后通过<条码>。 可以说,《刑法》更倾向于这样做:

List("a","b","c") foreach {println(_)}

甚至

List("a","b","c") foreach {s => println(s)}

Personally, when I see code that isn t written in point-free style, I take it as an indicator that the bound name may be used twice, or that it has some significance in documenting the code. Likewise, I see point-free style as a sign that I can reason about the code more simply.

问题回答

一种无点风格的一般呼吁是,没有环绕的“点”(价值而不是功能)的浮板,必须在几个地方重复通过计算加以校服,因此犯错误的机会较少,例如,在打上变数的名称时。

然而,在Schala,由于电离层能力微薄而迅速抵消了无分点的好处,由于“点”是干扰型推器的指摘器,因此,这种无分法又加剧了这种情况。 在Haskell,由于其几乎完全的刺激类型,这通常不是一个问题。

我看不出“特权”以外的其他好处: 略微缩短了,可能更可读。 它允许说明作为实体的职能,而没有精神上“更深层”的职能应用,但当然,你首先需要加以利用。

我不了解通过使用业绩改进业绩的任何例子(如果你在使用方法足够时以职能结束,情况可能更糟)。





相关问题
How to flatten a List of different types in Scala?

I have 4 elements:List[List[Object]] (Objects are different in each element) that I want to zip so that I can have a List[List[obj1],List[obj2],List[obj3],List[obj4]] I tried to zip them and I ...

To use or not to use Scala for new Java projects? [closed]

I m impressed with Twitter and investigating to use Scala for a new large scale web project with Hibernate and Wicket. What do you think about Scala, and should I use it instead of Java? EDIT: And, ...

Why does Scala create a ~/tmp directory when I run a script?

When I execute a Scala script from the command line, a directory named "tmp" is created in my home directory. It is always empty, so I simply deleted it without any apparent problem. Of course, when I ...

Include jar file in Scala interpreter

Is it possible to include a jar file run running the Scala interpreter? My code is working when I compile from scalac: scalac script.scala -classpath *.jar But I would like to be able to include a ...

Scala and tail recursion

There are various answers on Stack Overflow which explain the conditions under which tail recursion is possible in Scala. I understand the limitations and how and where I can take advantage of tail ...

热门标签