Haskell 函数组合 (.) 和函数应用 ($) 习语:正确使用 [英] Haskell function composition (.) and function application ($) idioms: correct use

查看:29
本文介绍了Haskell 函数组合 (.) 和函数应用 ($) 习语:正确使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读Real World Haskell,并且接近尾声,但是风格问题一直困扰着我与(.)($) 运算符.

I have been reading Real World Haskell, and I am nearing the end, but a matter of style has been niggling at me to do with the (.) and ($) operators.

当你编写一个由其他函数组成的函数时,你可以这样写:

When you write a function that is a composition of other functions you write it like:

f = g . h

但是当你在这些函数的末尾应用一些东西时,我是这样写的:

But when you apply something to the end of those functions I write it like this:

k = a $ b $ c $ value

但是这本书会这样写:

k = a . b . c $ value

现在,在我看来,它们在功能上是等效的,它们在我眼中的作用完全相同.然而,我看得越多,就越能看到人们以本书的方式编写函数:首先使用 (.) 组合,然后仅在最后使用 ($) 附加一个值来评估批次(没有人用很多美元组合来计算).

Now, to me they look functionally equivalent, they do the exact same thing in my eyes. However, the more I look, the more I see people writing their functions in the manner that the book does: compose with (.) first and then only at the end use ($) to append a value to evaluate the lot (nobody does it with many dollar compositions).

是否有理由使用比使用所有 ($) 符号更好的书籍方式?或者这里有一些我没有得到的最​​佳实践吗?或者它是多余的,我根本不应该担心它?

Is there a reason for using the books way that is much better than using all ($) symbols? Or is there some best practice here that I am not getting? Or is it superfluous and I shouldn't be worrying about it at all?

推荐答案

我想我可以从权威那里回答这个问题.

I guess I can answer this from authority.

是否有理由使用比使用所有 ($) 符号更好的书籍方式?

Is there a reason for using the books way that is much better than using all ($) symbols?

没有什么特别的原因.Bryan 和我都喜欢减少线路噪音..$ 更安静.因此,本书使用了 f .G .h $ x 语法.

There's no special reason. Bryan and I both prefer to reduce line noise. . is quieter than $. As a result, the book uses the f . g . h $ x syntax.

这篇关于Haskell 函数组合 (.) 和函数应用 ($) 习语:正确使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆