Why isn't `join` part of the `Monad` class [duplicate]

≡放荡痞女 提交于 2019-12-21 07:04:42

问题


It is a well known fact that (>>=) can be implemented using fmap and join while join can be implemented using >>=. Is there any reason we don't define the Monad class with join included and using the following default definitions?

join x  = x >>= id
x >>= f = join $ f <$> x

This would allow a minimal definition to include either just (>>=) or join, instead of forcing (>>=). Might be a bit helpful considering category theory tends to favour join.

The usual argument against modifying classes is that we break backwards compatibility. However, in this case, that wouldn't happen - we only add the possibility of defining Monad using join.


回答1:


That was meant to happen with the Applicative-Monad proposal (which has made it to GHC 7.10). However, there is a technical issue involving type roles in GHC which has postponed indefinitely the implementation of what you suggest.



来源:https://stackoverflow.com/questions/31552064/why-isnt-join-part-of-the-monad-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!