[英]Haskell: Is there an operator like this: (<$$>) :: Functor f => f a -> (a -> b) -> f b
Finding out that map and flat map in Haskell could be performed the this way, 可以通过这种方式找出Haskell中的地图和平面地图,
xs >>= f ≃ flatMap f xs
xs >>= return . f ≃ map f xs
I thought it would be convenient if we have such an operator 我以为如果有这样的操作员会很方便
(<$$>) :: Functor f => f a -> (a -> b) -> f b
f <$$> fn = fn <$> f
so that map could be expressed more tidily: 这样可以更整洁地表达地图:
xs >>= f ≃ flatMap f xs
xs <$$> f ≃ map f xs
Does such an operator exist in Haskell's standard library? Haskell的标准库中是否存在这样的运算符?
Note also that, as often to flip arguments, operator sections may be "enough" and may perhaps preserve readability by limiting the introduction of new operators: 还请注意,经常翻转参数时,运算符部分可能“足够”,并且可能会通过限制引入新的运算符来保持可读性:
> :{
| (<$> Just 0) $ \x ->
| x + 1 + 1 + 1
| + 1 + 1 + 1
| + 1 + 1 + 1
| + 1 + 1 + 1
| :}
Just 12
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.