简体   繁体   English

用没有括号的$重写`map(fgh)x`?

[英]Rewrite `map (f.g.h) x` with $ without parentheses?

I would like check whether we can't rewrite map (fgh) x with $ without parentheses as I didn't find a way. 我想检查一下我们是否无法用没有括号的$重写map (fgh) x

Here are my trials: 这是我的审判:

map (f.g.h) x
-> map (f.g.h) $ x  -- OK, no benefit
-> map $ f.g.h $ x  -- wrong as map doesn't take one parameter
-> (map $ f.g.h) x  -- Ok, no benefit, ugly :-)

Only elegant option I found was to use 我发现的唯一优雅的选择是使用

negate . sum . tail <$> [[1..5], [3..6]]]

but I would like to be sure that I didn't skip some options above. 但我想确保我没有跳过上面的一些选项。 Thank you 谢谢

how about? 怎么样?

let u = f.g.h in map u x

no parenthesis, no $ 没有括号,没有$

If you define the function 如果定义功能

map (f.g.h) x

You thus process each element of x with f . g . h 因此,您可以使用f . g . h处理x 每个元素f . g . h f . g . h f . g . h , this means that we first apply h on it, then g on the result, and finally f on that result. f . g . h ,这意味着我们首先对其应用h ,然后对结果应用g ,最后对该结果应用f

But we can also work with three separate map s, like: 但是我们也可以使用三个单独的map ,例如:

map f $ map g $ map h x

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

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