-- | The `MonadOr` type class has no members of its own but extends
-- | `MonadZero` with an additional law:
-- |
-- | - Left catch: `(return a) <|> b = return a`
class MonadZero m <= MonadOr m
But it adding MonadOr will introduce other issue: some structures could conform to MonadOr and MonadPlus and adding empty MonadOr will make it impossible to express that. See example from MonadPlus reform proposal#Instances of both
instance MonadPlus Maybe where
mplus (Just a) Nothing = Just a
mplus Nothing (Just a) = Just a
mplus _ _ = Nothing
instance MonadOr Maybe where
-- this is same as definition in Alternative
morelse (Just a) _ = Just a
morelse _ b = b
instance MonadOr [] where
morelse [] b = b
morelse a b = a
instance MonadPlus [] where
-- this is same as definition in Alternative
mplus = (++)
If we add MonadOr it should have function with different name then <|>, haskell proposal uses morelse. but except this, we should also add a function to MonadPlus too, as pointed above some structures supports both (Maybe or List).
Yes, I think we can safely say at this point that this class isn't in enough demand to deserve a spot in the core libraries, so I'm going to close this for now.
it would be nice to add
MonadOr
typeclass:For example IO could be an instance of
MonadOr
.But it adding MonadOr will introduce other issue: some structures could conform to MonadOr and MonadPlus and adding empty MonadOr will make it impossible to express that. See example from MonadPlus reform proposal#Instances of both
If we add MonadOr it should have function with different name then
<|>
, haskell proposal usesmorelse
. but except this, we should also add a function to MonadPlus too, as pointed above some structures supports both (Maybe or List).Related discussion in Fantasy Land