简体   繁体   English

“多参数”功能组合(例如fmap。fmap)如何工作?

[英]How does “multi-argument” functional composition work (e.g. fmap . fmap)?

When we have the expression: 当我们有表达式时:

(fmap . fmap) function nested_functor

I would expect it to translate to something like 我希望它会翻译成类似

fmap (fmap function nested_functor)

Though it surprisingly seems to behave as 尽管它似乎表现出令人惊讶的行为

fmap (fmap function) nested_functor

Why? 为什么?

Well, just look at the definition of (.) : 好吧,只看(.)的定义:

(f . g) x = f (g x)

So, 所以,

(fmap . fmap) function = fmap (fmap function)

Adding an additional argument at the end doesn't really change the equation -- just makes it more specific. 最后添加一个额外的参数并不会真正改变方程式-只是使其更加具体。

(fmap . fmap) function nested_functor = fmap (fmap function) nested_functor

(NB function application is left associative, so fxy means (fx) y .) (NB函数应用程序保持关联,因此fxy表示(fx) y 。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM