Skip to content

Add MonadZero and MonadPlus#5

Closed
garyb wants to merge 3 commits into
masterfrom
monadplus
Closed

Add MonadZero and MonadPlus#5
garyb wants to merge 3 commits into
masterfrom
monadplus

Conversation

@garyb

@garyb garyb commented May 19, 2014

Copy link
Copy Markdown
Member

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

joneshf commented May 19, 2014

Copy link
Copy Markdown
Member

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

garyb commented May 19, 2014

Copy link
Copy Markdown
Member Author

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

@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

paf31 commented May 19, 2014

Copy link
Copy Markdown
Contributor

👍 🚢

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

paf31 commented May 19, 2014

Copy link
Copy Markdown
Contributor

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

@garyb

garyb commented May 19, 2014

Copy link
Copy Markdown
Member Author

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

paf31 commented May 19, 2014

Copy link
Copy Markdown
Contributor

I think we'd have to, yes.

@garyb

garyb commented May 19, 2014

Copy link
Copy Markdown
Member Author

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

paf31 commented May 20, 2014

Copy link
Copy Markdown
Contributor

Yes I think so.

@paf31

paf31 commented May 20, 2014

Copy link
Copy Markdown
Contributor

Do we plan to include any instances?

@garyb

garyb commented May 20, 2014

Copy link
Copy Markdown
Member Author

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

garyb commented May 24, 2014

Copy link
Copy Markdown
Member Author

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