Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p136 (<$) #29

Open
boboyada opened this issue Jan 5, 2017 · 3 comments
Open

p136 (<$) #29

boboyada opened this issue Jan 5, 2017 · 3 comments

Comments

@boboyada
Copy link

boboyada commented Jan 5, 2017

(<$)=fmap . const
与 (<$)=fmap const
有什么区别?
1.前者是中间有个复合函数运算符
2.后者直接把const当作f函数,将f函数提升到函子盒子级别

@winterland1989
Copy link
Owner

winterland1989 commented Jan 6, 2017

看来你已经自问自答了😄 所以你的问题是? 另外(<$)=fmap const是出自哪里的定义?

@boboyada
Copy link
Author

boboyada commented Jan 6, 2017

magic-haskell ,P136页,
(<$) :: Functor f => a -> f b -> fa
(<$) = fmap (.) const

($>) ::Functor f => f a -> b -> f b
($&gt;) = flip (&lt;$)

这都是书上的定义呀。
我想询问的是
fmap (。) const
fmap const
这两个表达式有什么区别?

@winterland1989
Copy link
Owner

winterland1989 commented Jan 6, 2017

(<$)=fmap const

并不是出自书上的定义,我也没有在别的地方看到有定义这样的(<$)运算符。

1.前者是中间有个复合函数运算符
2.后者直接把const当作f函数,将f函数提升到函子盒子级别

这两个表达式的区别你不是说得挺清楚了嘛,两个表达式的含义很不同呀:

fmap (.) const == \ x y -> fmap (const x) y         -- 组合函数,先应用const,再应用fmap
fmap const == \ x -> fmap const x                      -- 部分应用,直接应用fmap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants