问题
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