简体   繁体   English

`bind`等同于加入(fmap fm)吗?

[英]`bind` Equivalent to join (fmap f m)?

This excellent answer in this question demonstrates how bind can be written in terms of join and fmap : 这个优秀的答案在这个问题演示了如何bind可以在以下方面进行书面joinfmap

(>>=) :: mv -> (v -> mw) -> mw

says "if you have a strategy to produce av, and for each va follow-on strategy to produce aw, then you have a strategy to produce aw". 说道:“如果您有产生av的策略,并且对于每个va后续策略都产生aw,那么您就有了产生aw的策略。” How can we capture that in terms of join? 我们如何才能在加入方面捕捉到这一点?

mv >>= v2mw = join (fmap v2mw mv)

But, I don't understand how v2mw , which has a type of a -> mb type checks to the first argument of fmap . 但是,我不明白v2mw (具有v2mw a -> mb类型的类型)如何检查fmap的第一个参数。

fmap :: Functor f => (a -> b) -> fa -> fb

Let's say v2mw :: c -> md , just so things aren't ambiguous, and 假设v2mw :: c -> md ,这样就不会造成歧义,并且

fmap :: Functor f => (a -> b) -> f a -> f b

Then fmap v2mw works out so that f ~ m , a ~ c and b ~ md , so 然后fmap v2mw作品出来,使得f ~ ma ~ cb ~ md ,所以

fmap v2mw :: m c -> m (m d)

and join :: m (me) -> me , so join (fmap v2mw mv) has type md as expected. join :: m (me) -> me ,因此join (fmap v2mw mv)类型为md符合预期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM