<$> 有什么用?在 Haskell 中是什么意思? [英] What does <$> mean in Haskell?

查看:28
本文介绍了<$> 有什么用?在 Haskell 中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读一段 Haskell 代码时,我发现了这个:<$>.它在 Haskell 中是什么意思?经过一些谷歌搜索后,我仍然一无所知.

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 不是 Haskell 的最佳搜索引擎.试试 Hoogle Hayoo,两者都会马上指出你到这个:

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

它只是的中缀同义词fmap,所以你可以写例如

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.

Hayoo 离线有一段时间了.

这篇关于&lt;$&gt; 有什么用?在 Haskell 中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆