在朱莉娅(Julia),一个人可以在haskell术语中写下“章节”中的内容吗?
根据 haskell …
在Haskell中,infix操作员的部分应用称为部分。
考虑Haskell Expression 过滤器(\ n - > n> 0)[-3,-4,5,6,-7,8]
,它评估为[5,6 ,8]
。
使用 节 ,可以在haskell中重写为filter(> 0)[-3,-4,5,6,-7,-7, 8]
。
在 Julia 中,可以写filter(n - > n> 0,[-3,-4,5,6,-7,8] )
。
可以使用Haskell部分(> 0)
在Julia中重新编写这最后写吗?
以下会产生语法错误……
filter( (>0), [-3,-4,5,6,-7,8] )
更新
,在Haskell中可以重新编写…
过滤器(\ list - >长度列表> 2)[[2,3],[5,7,11],[13],[17,19,23,29]]
…作为 …
过滤器((> 2).length)[[2,3],[5,7,11],[13],[17,19,23,29]]
< /p>
in Julia ,可以使用部分和函数组成类似地重写吗?
According to A Gentle Introduction to Haskell …
In Haskell the partial application of an infix operator is called a section.
Consider the Haskell expression filter (\n -> n > 0) [-3,-4,5,6,-7,8]
, which evaluates to [5,6,8]
.
Using a section, this may be re-written in Haskell as filter (>0) [-3,-4,5,6,-7,8]
.
In Julia, one may write filter( n -> n > 0, [-3,-4,5,6,-7,8] )
.
Can this last be re-written in Julia using an equivalent of the Haskell section (>0)
?
The following yields a syntax error …
filter( (>0), [-3,-4,5,6,-7,8] )
Update
Also, in Haskell one can re-write …
filter (\list -> length list > 2) [ [2,3], [5,7,11], [13], [17,19,23,29] ]
… as …
filter ((>2).length) [ [2,3], [5,7,11], [13], [17,19,23,29] ]
In Julia, can one similarly re-write, using a section and function composition?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不是句法,否。但是,一些操作员有用于部分应用“逻辑”参数的方法,在这些比较运算符中,从基本的所有比较运算符中:
但是,一个可以自由编写实现某些语法技巧的宏。例如,来自 underscores.jl :
Not syntactically, no. But some operators have methods for partial application of the "logical" argument, among these all the comparison operators from Base:
However, one is free to write macros that implement some syntactic tricks. E.g., from Underscores.jl:
对于您的第一个景象,您可以写作:
这是有效的,因为根据帮助:
因此,如果您想要第二个景象类似的东西,则可能需要定义自己的类似功能:
然后您可以做:
但是,是否是一个好主意,或者不仅为某些糖连接的定制功能创建自定义功能将取决于您。您最终可能需要编码宏来简化此任务。
For your first exemple, you can write:
This works because according to the help:
So if you want something similar for your second exemple, you may need to define yourself a similar function like this:
And then you can do:
However, whether it is a good idea or not to create custom functions just for some sugar-syntaxing will be up to you. You may eventually want to code macro to simplify this task.