需要知道什么是< *> < $>和。在哈斯克尔做 [英] need to know what <*> <$> and . do in haskell
问题描述
(。)::(b - > c) - > (a - > b) - > a - > c
(< $>):: Functor f => (a - > b) - > f a - > f b
(*)::适用的f => f(a - > b) - > f a - > f b
可以吗?我没有任何想法,当我看到签名,perhabs一些简单和易于理解的解释的例子将帮助我。
我也在学习Haskell,我的建议是看看了解你对Haskell的好处!,更准确地说:
- 用于
(。)
读取功能组合 - 用于
< $>
和<>
阅读 Applicative仿函数
实质上:
(。)
是函数组合:如果您有 g :: a - > b
和 f :: b - > c
然后 f。 g
本质上是 f(g(x))
:首先使用 g
code> a 来得到一个 b
,然后使用 f
code> b 得到 c
< $>
取一个函数,它取一个 a
并返回一个 b
和一个函数包含一个 a
,并且它返回一个函数包含一个 b
。因此< $>
与 fmap ::(a - > b) - >相同。 f a - > fb
<>
>包含一个函数,它带一个 a
并返回一个 b
,一个函数包含一个 a
,它返回一个包含 a b
的函子。所以<>< / code>< em>< em>>< em>进入仿函数
注意在本书章节中找到的解释优于我上面的尝试
hi guys can someone explain me as a haskell noob what the the operators:
(.) :: (b -> c) -> (a -> b) -> a -> c
(<$>) :: Functor f => (a -> b) -> f a -> f b
(<*>) :: Applicative f => f (a -> b) -> f a -> f b
do? i dont have any idea when i see the signatures, perhabs some example with a simple and easy to understand explanation will help me.
I am also learning Haskell, and my recommendation is to have a look into Learn You a Haskell for Great Good!, and more precisely:
- for
(.)
read Function composition - for
<$>
and<*>
read Applicative functors
In essence:
(.)
is function composition: if you haveg :: a -> b
andf :: b -> c
thenf . g
is essentiallyf(g(x))
: first useg
on ana
to get ab
and then usef
on thatb
to get ac
<$>
takes a function taking ana
and returning ab
, and a functor that contains ana
, and it returns a functor that contains ab
. So<$>
is the same asfmap :: (a -> b) -> f a -> f b
<*>
takes a functor that contains a function taking ana
and returning ab
, and a functor that contains ana
, and it returns a functor that contains ab
. So<*>
kind of extract the function from a functor and applies it to an arguments also inside a functor, and finally returns the result into a functor
Note the explanations that you find in the book chapters are better than my attempt above
这篇关于需要知道什么是< *> < $>和。在哈斯克尔做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!