[英]What does <$> mean in Haskell?
While reading a piece of Haskell code I came upon this: <$>
. 在阅读一段Haskell代码时,我发现了这个:
<$>
。 What does it mean in Haskell? 在Haskell中它意味着什么? After some google searches I remain in the dark.
经过一些谷歌搜索,我仍然在黑暗中。
Google is not the best search engine for Haskell. 谷歌不是Haskell最好的搜索引擎。 Try Hoogle
试试Hoogle
or Hayoo † , both will point you right away to this: 或者哈尤
† ,两者都会立即指出你:
(<$>) :: Functor f => (a->b) -> f a -> f b
It's merely an infix synonym for fmap
, so you can write eg 它只是
fmap
的中缀同义词,所以你可以写例如
Prelude> (*2) <$> [1..3]
[2,4,6]
Prelude> show <$> Just 11
Just "11"
Like most infix functions, it is not built-in syntax, just a function definition. 像大多数中缀函数一样,它不是内置语法,只是函数定义。 But functors are such a fundamental tool that
<$>
is found pretty much everywhere. 但是仿函数是一种基本工具,
<$>
几乎无处不在。
† Hayoo has been offline for quite a while now. † Hayoo已经离线了很长一段时间了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.