Skip to content
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

Add MonadZero and MonadPlus #5

Closed
wants to merge 3 commits into from
Closed

Add MonadZero and MonadPlus #5

wants to merge 3 commits into from

Conversation

garyb
Copy link
Member

@garyb garyb commented May 19, 2014

I don't know if we want to lay down a consistent set of laws for MonadPlus, but left distribution seems to make sense to me over left catch, given that an Alternative instance can be used for left catch instead (I think?).

MonadZero as a separate class seems useful too, as we don't have fail in our Monad, and also it matches how we do things with ArrowZero and ArrowPlus.

@joneshf
Copy link
Member

joneshf commented May 19, 2014

I'm not too well versed on the whole MonadPlus, MonadZero, MonadOr deal, but isn't Alternative supposed to be a superclass for one of these?

Either way, I'm for this.

@garyb
Copy link
Member Author

garyb commented May 19, 2014

I don't think it's supposed to be a superclass as there are cases that can't satisfy both left catch and left distribution. I'm not super well versed in the discussion either, just going off this for the most part.

@jdegoes or @puffnfresh have any thoughts on this?

@puffnfresh
Copy link

@garyb I think Alternative would be a super-class for MonadOr, which is left out of this.

I also recommend reading this awesome blog post:

http://winterkoninkje.dreamwidth.org/90905.html

@paf31
Copy link
Contributor

paf31 commented May 19, 2014

👍 🚢

Maybe we should move Alternative into control as well. I don't think it's used in Prelude.

Also, then we can add a few more primitives like some and many in a new Control.Alternative module.

Are there any standard things like that for MonadZero or MonadPlus?

@paf31
Copy link
Contributor

paf31 commented May 19, 2014

Also 👍 for breaking up Alternative if it can be done easily.

@garyb
Copy link
Member Author

garyb commented May 19, 2014

I think we have Alternative instances defined in a few of the other core libraries so I guess we'd move those in here too then?

@paf31
Copy link
Contributor

paf31 commented May 19, 2014

I think we'd have to, yes.

@garyb
Copy link
Member Author

garyb commented May 19, 2014

Is this OK to merge in its current state then, given that neither of these classes are affected by changes needed for MonadOr or Alternative?

I don't think there are any functions like some or many to go along with MonadPlus, aside from guard, which I've just added. There's also msum, but that should probably go with Foldable.

@paf31
Copy link
Contributor

paf31 commented May 20, 2014

Yes I think so.

@paf31
Copy link
Contributor

paf31 commented May 20, 2014

Do we plan to include any instances?

@garyb
Copy link
Member Author

garyb commented May 20, 2014

I was thinking about that, I think instances should go in the modules that define the types that are suitable. At the moment purescript-control has no dependencies, so it would seem sensible to keep it that way and have things depend on it.

As far as I know, the only instances we need for standard types are for Array and Maybe, and perhaps something like Error e <= Either e.

Array and Maybe are also Alternative, so adding the dependency to purescript-control on the data side would make sense for that too.

@garyb
Copy link
Member Author

garyb commented May 24, 2014

More related discussion at #6

@garyb garyb closed this May 24, 2014
@garyb garyb deleted the monadplus branch August 9, 2014 11:47
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

Successfully merging this pull request may close these issues.

4 participants