Haskell的“胸部操作员”以简单的非功能性英语工作? [英] How does Haskell's "boobs operator" work in plain non-functional English?

查看:118
本文介绍了Haskell的“胸部操作员”以简单的非功能性英语工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这个答案 https://stackoverflow.com/a/11006842/1065190 中提到了一个猫头鹰操作符 :

  absoluteError =((。)。(。))abs( - )

以无点记法表达绝对误差函数。



无论如何,这个表示法实际上有效吗?

请问你把它解释给一个非功能性的C ++程序员吗?

(。)。(。),也写成(。:)有时候,是在右侧组成的函数有两个缺失参数时的函数组合。如果您尝试直接使用(。),它不会检查,尽管由于功能性管道的理念,它非常诱人。






另外,值得考虑(。:)是否与 Data.Function.on

 翻转::(a  - > ; b) - > (b→b→c)→> (a  - > a  - > c)
(。:) ::(a - > b) - > (c - > d - > a) - > (c - > d - > b)

on 使用一元函数来转换二元函数的两个输入。 (。:)采用二元函数并用它将一元函数转换为二元函数。


In this answer https://stackoverflow.com/a/11006842/1065190 an "owl operator" is mentioned:

absoluteError = ((.) . (.)) abs (-)

to express the absolute error function in point-free notation.

Anyway, how does this notation actually work?

Could you, please, explain it to a non-functional C++ programmer?

解决方案

As simply as possible (.).(.), also written (.:) sometimes, is function composition when the function being composed on the right side has two missing arguments. If you try to use (.) directly it doesn't typecheck, although it's quite tempting due to an idea of functional "plumbing".


Also, it's worth thinking about how (.:) is kind of the plumbing opposite of Data.Function.on.

flip on :: (a -> b) -> (b -> b -> c) -> (a -> a -> c)
(.:)    :: (a -> b) -> (c -> d -> a) -> (c -> d -> b)

on uses a unary function to transform the two inputs of a binary function. (.:) takes a binary function and uses it to transform a unary function into a binary function.

这篇关于Haskell的“胸部操作员”以简单的非功能性英语工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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