Skip to content

Add MonadOr? #35

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

Closed
safareli opened this issue Oct 31, 2016 · 2 comments
Closed

Add MonadOr? #35

safareli opened this issue Oct 31, 2016 · 2 comments

Comments

@safareli
Copy link

safareli commented Oct 31, 2016

it would be nice to add MonadOr typeclass:

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

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

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).

Related discussion in Fantasy Land

@anilanar
Copy link

Shall this be closed?

@hdgarrood
Copy link
Contributor

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.

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

3 participants