什么是< $>在Haskell中意味着什么? [英] What does <$> mean in Haskell?
问题描述
在阅读一段Haskell代码时,我遇到了这个问题:< $>
。 Haskell意味着什么?谷歌并不是Haskell的最佳搜索引擎。谷歌并不是Haskell的最佳搜索引擎。谷歌并不是Haskell的最佳搜索引擎。尝试 Hoogle 或 Hayoo ,两者都会立即指示你 to this:
(< $>):: Functor f => (a-> b) - > f a - > fb
它只是一个中缀的同义词 fmap
,因此您可以编写例如
Prelude> (* 2)< $> [1..3]
[2,4,6]
前奏>显示< $>只是11
只是11
像大多数中缀函数一样,它不是 内置语法,只是一个函数定义。但仿函数是一个基本的工具,几乎可以找到< $>
。
While reading a piece of Haskell code I came upon this: <$>
. What does it mean in Haskell? After some google searches I remain in the dark.
Google is not the best search engine for Haskell. Try 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 e.g.
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.
这篇关于什么是< $>在Haskell中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!