Adding more instances to Kleisli: Generic, Monad, etc

This is another part of https://gitlab.haskell.org/ghc/ghc/merge_requests/644, which is presumably much less controversial: Generic (Kleisli m a b) Functor m => Functor (Kleisli m a) Applicative m => Applicative (Kleisli m a) Alternative m => Alternative (Kleisli m a) Monad m => Monad (Kleisli m a) (Alternative m, Monad m) => MonadPlus (Kleisli m a)

I think the MonadPlus instance should probably have a MonadPlus constraint,
since MonadPlus makes a sort of statement about the interaction between >>=
and mplus, even if it's a bit of an ambiguous one.
On Tue, Apr 2, 2019, 12:30 AM Fumiaki Kinoshita
This is another part of https://gitlab.haskell.org/ghc/ghc/merge_requests/644, which is presumably much less controversial:
Generic (Kleisli m a b) Functor m => Functor (Kleisli m a) Applicative m => Applicative (Kleisli m a) Alternative m => Alternative (Kleisli m a) Monad m => Monad (Kleisli m a) (Alternative m, Monad m) => MonadPlus (Kleisli m a) _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

I'm not quite sure what the point of MonadPlus is; the default definitions
are the Alternative methods. Would we ever want to have MonadPlus different
from Alternative?
2019年4月2日(火) 13:44 David Feuer
I think the MonadPlus instance should probably have a MonadPlus constraint, since MonadPlus makes a sort of statement about the interaction between >>= and mplus, even if it's a bit of an ambiguous one.
On Tue, Apr 2, 2019, 12:30 AM Fumiaki Kinoshita
wrote: This is another part of https://gitlab.haskell.org/ghc/ghc/merge_requests/644, which is presumably much less controversial:
Generic (Kleisli m a b) Functor m => Functor (Kleisli m a) Applicative m => Applicative (Kleisli m a) Alternative m => Alternative (Kleisli m a) Monad m => Monad (Kleisli m a) (Alternative m, Monad m) => MonadPlus (Kleisli m a) _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

The issue is that you can't prove that whicher set of MonadPlus laws you
are using _follows_ from whichever set of Alternative laws you are using.
This discussion is somewhat hampered by neither one having a well-written
set of laws, because we use MonadPlus in two or three mutually incompatible
ways and for the most part "it just works" so people don't notice.
Consider the space of laws mentioned in:
https://wiki.haskell.org/MonadPlus_reform_proposal
These don't necessarily follow from any of the popular Alternative law
proposals.
Left Zero:
On the Applicative side you can do more to explore the tree, can "run"
effects right to left, etc.
We have a _left_ zero law for a monadplus:
mzero >>= f = mzero
but not a right one, just because of the existence of the function space in
(>>=) that we can't see through
(do putStrLn "die"; mzero) /= mzero
But nothing keeps us from seeing through an (*>) to count up something on
the right. Control.Applicative.Backwards exists and would satisfy a "right
zero" law if the original satisfied a left zero law.
Left Distribution:
Similarly, you can imagine a data type that is Alternative and also a
Monad, but where
mplus a b >>= k = mplus (a >>= k) (b >>= k)
fails to hold in the left distributive style, and it also fails to be in
the left catch style.
Without _retiring_ MonadPlus, we should at least use it consistently to
imply the requirement of this sort of extra structure, even if it is
ambiguous what that structure should be.
-Edward
On Wed, Apr 3, 2019 at 3:16 AM Fumiaki Kinoshita
I'm not quite sure what the point of MonadPlus is; the default definitions are the Alternative methods. Would we ever want to have MonadPlus different from Alternative?
2019年4月2日(火) 13:44 David Feuer
: I think the MonadPlus instance should probably have a MonadPlus constraint, since MonadPlus makes a sort of statement about the interaction between >>= and mplus, even if it's a bit of an ambiguous one.
On Tue, Apr 2, 2019, 12:30 AM Fumiaki Kinoshita
wrote: This is another part of https://gitlab.haskell.org/ghc/ghc/merge_requests/644, which is presumably much less controversial:
Generic (Kleisli m a b) Functor m => Functor (Kleisli m a) Applicative m => Applicative (Kleisli m a) Alternative m => Alternative (Kleisli m a) Monad m => Monad (Kleisli m a) (Alternative m, Monad m) => MonadPlus (Kleisli m a) _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

I see... Thanks for the explanation, I updated the patch.
2019年4月4日(木) 4:46 Edward Kmett
The issue is that you can't prove that whicher set of MonadPlus laws you are using _follows_ from whichever set of Alternative laws you are using.
This discussion is somewhat hampered by neither one having a well-written set of laws, because we use MonadPlus in two or three mutually incompatible ways and for the most part "it just works" so people don't notice.
Consider the space of laws mentioned in:
https://wiki.haskell.org/MonadPlus_reform_proposal
These don't necessarily follow from any of the popular Alternative law proposals.
Left Zero:
On the Applicative side you can do more to explore the tree, can "run" effects right to left, etc.
We have a _left_ zero law for a monadplus:
mzero >>= f = mzero
but not a right one, just because of the existence of the function space in (>>=) that we can't see through
(do putStrLn "die"; mzero) /= mzero
But nothing keeps us from seeing through an (*>) to count up something on the right. Control.Applicative.Backwards exists and would satisfy a "right zero" law if the original satisfied a left zero law.
Left Distribution:
Similarly, you can imagine a data type that is Alternative and also a Monad, but where
mplus a b >>= k = mplus (a >>= k) (b >>= k)
fails to hold in the left distributive style, and it also fails to be in the left catch style.
Without _retiring_ MonadPlus, we should at least use it consistently to imply the requirement of this sort of extra structure, even if it is ambiguous what that structure should be.
-Edward
On Wed, Apr 3, 2019 at 3:16 AM Fumiaki Kinoshita
wrote: I'm not quite sure what the point of MonadPlus is; the default definitions are the Alternative methods. Would we ever want to have MonadPlus different from Alternative?
2019年4月2日(火) 13:44 David Feuer
: I think the MonadPlus instance should probably have a MonadPlus constraint, since MonadPlus makes a sort of statement about the interaction between >>= and mplus, even if it's a bit of an ambiguous one.
On Tue, Apr 2, 2019, 12:30 AM Fumiaki Kinoshita
wrote: This is another part of https://gitlab.haskell.org/ghc/ghc/merge_requests/644, which is presumably much less controversial:
Generic (Kleisli m a b) Functor m => Functor (Kleisli m a) Applicative m => Applicative (Kleisli m a) Alternative m => Alternative (Kleisli m a) Monad m => Monad (Kleisli m a) (Alternative m, Monad m) => MonadPlus (Kleisli m a) _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

Any +1/-1s?
2019年4月2日(火) 13:30 Fumiaki Kinoshita
This is another part of https://gitlab.haskell.org/ghc/ghc/merge_requests/644, which is presumably much less controversial:
Generic (Kleisli m a b) Functor m => Functor (Kleisli m a) Applicative m => Applicative (Kleisli m a) Alternative m => Alternative (Kleisli m a) Monad m => Monad (Kleisli m a) (Alternative m, Monad m) => MonadPlus (Kleisli m a)

I am +1 on this.
On Sun, Apr 7, 2019, 4:31 AM Fumiaki Kinoshita
Any +1/-1s?
2019年4月2日(火) 13:30 Fumiaki Kinoshita
: This is another part of https://gitlab.haskell.org/ghc/ghc/merge_requests/644, which is presumably much less controversial:
Generic (Kleisli m a b) Functor m => Functor (Kleisli m a) Applicative m => Applicative (Kleisli m a) Alternative m => Alternative (Kleisli m a) Monad m => Monad (Kleisli m a) (Alternative m, Monad m) => MonadPlus (Kleisli m a)
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

I am also +1
On Mon, 8 Apr 2019 at 02:47, chessai .
I am +1 on this.
On Sun, Apr 7, 2019, 4:31 AM Fumiaki Kinoshita
wrote: Any +1/-1s?
2019年4月2日(火) 13:30 Fumiaki Kinoshita
: This is another part of https://gitlab.haskell.org/ghc/ghc/merge_requests/644, which is presumably much less controversial:
Generic (Kleisli m a b) Functor m => Functor (Kleisli m a) Applicative m => Applicative (Kleisli m a) Alternative m => Alternative (Kleisli m a) Monad m => Monad (Kleisli m a) (Alternative m, Monad m) => MonadPlus (Kleisli m a)
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
participants (5)
-
chessai .
-
David Feuer
-
Edward Kmett
-
Fumiaki Kinoshita
-
George Wilson