Adding more instances to Kleisli: Generic, Monad, etc

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding more instances to Kleisli: Generic, Monad, etc

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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Adding more instances to Kleisli: Generic, Monad, etc

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 <[hidden email]> 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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Adding more instances to Kleisli: Generic, Monad, etc

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 <[hidden email]>:
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 <[hidden email]> 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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Adding more instances to Kleisli: Generic, Monad, etc

Edward Kmett-2
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 <[hidden email]> 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 <[hidden email]>:
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 <[hidden email]> 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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Adding more instances to Kleisli: Generic, Monad, etc

Fumiaki Kinoshita
I see... Thanks for the explanation, I updated the patch.

2019年4月4日(木) 4:46 Edward Kmett <[hidden email]>:
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 <[hidden email]> 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 <[hidden email]>:
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 <[hidden email]> 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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Adding more instances to Kleisli: Generic, Monad, etc

Fumiaki Kinoshita
In reply to this post by Fumiaki Kinoshita
Any +1/-1s?

2019年4月2日(火) 13:30 Fumiaki Kinoshita <[hidden email]>:
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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Adding more instances to Kleisli: Generic, Monad, etc

chessai .
I am +1 on this.

On Sun, Apr 7, 2019, 4:31 AM Fumiaki Kinoshita <[hidden email]> wrote:
Any +1/-1s?

2019年4月2日(火) 13:30 Fumiaki Kinoshita <[hidden email]>:
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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Adding more instances to Kleisli: Generic, Monad, etc

George Wilson
I am also +1

On Mon, 8 Apr 2019 at 02:47, chessai . <[hidden email]> wrote:

>
> I am +1 on this.
>
> On Sun, Apr 7, 2019, 4:31 AM Fumiaki Kinoshita <[hidden email]> wrote:
>>
>> Any +1/-1s?
>>
>> 2019年4月2日(火) 13:30 Fumiaki Kinoshita <[hidden email]>:
>>>
>>> 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
>> [hidden email]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Adding more instances to Kleisli: Generic, Monad, etc

Ryan Scott
In reply to this post by Fumiaki Kinoshita
+1 from me, although I find it somewhat curious that this proposes adding a Generic instance, but not a Generic1 instance. Perhaps that should be included in the patch as well?

Ryan S.

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Adding more instances to Kleisli: Generic, Monad, etc

David Feuer
Yes, obviously.

On Mon, Apr 8, 2019, 9:29 AM Ryan Scott <[hidden email]> wrote:
+1 from me, although I find it somewhat curious that this proposes adding a Generic instance, but not a Generic1 instance. Perhaps that should be included in the patch as well?

Ryan S.
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries