是否可以在F#中编写默认函数
默认或无点风格编程允许人们创建函数而不考虑它们的参数。这可以在 F# 中完成吗?
Tacit or point-free style programming allows one to create functions without regard to their arguments. Can this be done in F#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是为了配合查克的回答&克里斯史密斯的评论,你可以写
当你结合这些成分和具有高阶函数的管道运算符,您可以非常简洁地完成复杂的事情:
编辑:我刚刚读到有关 J 及其隐式分叉运算符的信息。那是非常强大的。您可以在 F# 中构建等效的高阶运算符,但它们不会隐式应用。因此,例如,首先定义
lift
(使用显式参数),然后显式应用它
以获得类似于 您链接到的维基百科页面上的 J 示例。但它并不完全“默契”。
Just to go with Chuck's answer & Chris Smiths' comment, you could write
When you combine those composition & pipeline operators with higher-order functions, you can do complicated stuff very succinctly:
EDIT: I just read about J and its implicit fork operator. That is very powerful. You can build equivalent higher-order operators in F#, but they won't be applied implicitly. So, for example, first define
lift
(using explicit arguments)and then apply it explicitly
to get something resembling the J example on the Wikipedia page you linked to. But its not quite "tacit."
当然。您所需要的只是函数组合和柯里化,而这两者在 F# 中都是可能的。
Sure. All you need is function composition and currying, and both of these are possible in F#.