<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div name="messageBodySection">
<div dir="auto">I think that the counterexample I linked should be enough to rule out any instance for monad, in fact, in conjunction with the fact that to make liftA2 (,) correspond to zip, we need to have the join operation result in something which is the minimum of the length of the enclosing ziplist and all “enclosed” ziplists. <br />
<br />
I think but haven’t proven that it is the case that not only is infinite ziplist (i.e. “stream”) a monad, and every fixed-size ziplist a monad, but also ziplist is “categorically” a monad if we consider only functions a -> m b which are natural with regards to list length. I.e. ZipVect N is a graded monad under the min monoid.<br />
<br />
At one point I think I worked out, but haven’t found the code, that a cps-transformed ziplist can be made a monad (or at least overcome the counterexample), through fixing associativity by forcing reassociation of all binds (a la Voigtlander’s codensity trick).  If that works, it’s a nice curiosity, but I don’t think people are really crying out with a use case for a “proper” monad for ziplist anyway.<br />
<br />
-g</div>
</div>
<div name="messageReplySection">On Jun 4, 2020, 12:43 PM -0400, Gershom B <gershomb@gmail.com>, wrote:<br />
<blockquote type="cite" style="border-left-color: grey; border-left-width: thin; border-left-style: solid; margin: 5px 5px;padding-left: 10px;">
<div name="messageBodySection">
<div dir="auto">I know of counterexamples that show why the “obvious” instances don’t work. One nice one is here:<br />
<br />
<a href="https://www.reddit.com/r/haskell/comments/nfyvy/instance_monad_ziplist_where/c38x9q9?utm_source=share&utm_medium=web2x" target="_blank">https://www.reddit.com/r/haskell/comments/nfyvy/instance_monad_ziplist_where/c38x9q9?utm_source=share&utm_medium=web2x</a><br />
<br />
But I don’t know of a simple full proof of why no such instance is possible. My guess would be that we should consider the action of the operations on lengths of lists, and show that the requirements for monad and ziplist conflict.<br />
<br />
-g</div>
</div>
<div name="messageReplySection">On Jun 4, 2020, 11:57 AM -0400, David Feuer <david.feuer@gmail.com>, wrote:<br />
<blockquote type="cite" style="border-left-color: grey; border-left-width: thin; border-left-style: solid; margin: 5px 5px;padding-left: 10px;">
<div dir="auto">To add documentation, we need an explanation of *why* it's impossible.</div>
<br />
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Thu, Jun 4, 2020, 11:35 AM chessai . <<a href="mailto:chessai1996@gmail.com">chessai1996@gmail.com</a>> wrote:<br /></div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="auto">Agreed, that would be a great addition.</div>
<br />
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Thu, Jun 4, 2020, 8:31 AM Simon Jakobi <<a href="mailto:simon.jakobi@googlemail.com" target="_blank" rel="noreferrer">simon.jakobi@googlemail.com</a>> wrote:<br /></div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This sounds worth documenting though.<br />
<br />
Dannyu, would you be interested in updating the ZipList docs to say<br />
why it doesn't have a Monad instance?<br />
<br />
Cheers,<br />
Simon<br />
<br />
Am Do., 4. Juni 2020 um 17:21 Uhr schrieb chessai . <<a href="mailto:chessai1996@gmail.com" rel="noreferrer noreferrer" target="_blank">chessai1996@gmail.com</a>>:<br />
><br />
> David is right. This can't happen, unfortunately<br />
><br />
> On Thu, Jun 4, 2020, 12:48 AM David Feuer <<a href="mailto:david.feuer@gmail.com" rel="noreferrer noreferrer" target="_blank">david.feuer@gmail.com</a>> wrote:<br />
>><br />
>> I don't remember why right now, but it's moderately well-known that there is no possible Monad instance compatible with the Applicative instance for ZipList. See the answers to <a href="https://stackoverflow.com/questions/6463058/help-on-writing-the-colist-monad-exercise-from-an-idioms-intro-paper" rel="noreferrer noreferrer noreferrer" target="_blank">https://stackoverflow.com/questions/6463058/help-on-writing-the-colist-monad-exercise-from-an-idioms-intro-paper</a> by pigworker (Conor McBride) and C. A. McCann.<br />
>><br />
>> On Thu, Jun 4, 2020, 2:53 AM Dannyu NDos <<a href="mailto:ndospark320@gmail.com" rel="noreferrer noreferrer" target="_blank">ndospark320@gmail.com</a>> wrote:<br />
>>><br />
>>> instance Monad ZipList where<br />
>>>     ZipList [] >>= _ = ZipList []<br />
>>>     ZipList (x:xs) >>= f = ZipList $ do<br />
>>>         let ZipList y' = f x<br />
>>>         guard (not (null y'))<br />
>>>         let ZipList ys = ZipList xs >>= ZipList . join . maybeToList . fmap snd . uncons . getZipList . f<br />
>>>         head y' : ys<br />
>>><br />
>>> instance MonadFail ZipList where<br />
>>>     fail _ = empty<br />
>>><br />
>>> instance MonadPlus ZipList<br />
>>> _______________________________________________<br />
>>> Libraries mailing list<br />
>>> <a href="mailto:Libraries@haskell.org" rel="noreferrer noreferrer" target="_blank">Libraries@haskell.org</a><br />
>>> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br />
>><br />
>> _______________________________________________<br />
>> Libraries mailing list<br />
>> <a href="mailto:Libraries@haskell.org" rel="noreferrer noreferrer" target="_blank">Libraries@haskell.org</a><br />
>> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br />
><br />
> _______________________________________________<br />
> Libraries mailing list<br />
> <a href="mailto:Libraries@haskell.org" rel="noreferrer noreferrer" target="_blank">Libraries@haskell.org</a><br />
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br /></blockquote>
</div>
</blockquote>
</div>
_______________________________________________<br />
Libraries mailing list<br />
Libraries@haskell.org<br />
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries<br /></blockquote>
</div>
_______________________________________________<br />
Libraries mailing list<br />
Libraries@haskell.org<br />
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries<br /></blockquote>
</div>
</body>
</html>