为什么``加入``Monad`类的一部分 [英] Why isn't `join` part of the `Monad` class
问题描述
众所周知,(>> =)
可以使用 fmap
和 join
,而 join
可以使用>> =
。是否有任何理由我们没有定义包含 join
的 Monad
类并使用下列默认定义?
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
这将允许最小定义包含(>> ; =)
或 join
,而不是强制(>> =)
。考虑到类别理论倾向于支持 join
。
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
.
反对修改类的常见论据是我们打破向后兼容性。但是,在这种情况下,这种情况不会发生 - 我们只添加使用 join
来定义 Monad
的可能性。
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
.
推荐答案
这意味着要发生 Applicative-Monad提案(已将其提交给GHC 7.10)。但是,技术问题涉及在GHC中键入角色,它已无限期地推迟了您的建议。
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.
这篇关于为什么``加入``Monad`类的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!