Add instance Monad ZipList

chessai . chessai1996 at gmail.com
Thu Jun 4 15:21:04 UTC 2020


David is right. This can't happen, unfortunately

On Thu, Jun 4, 2020, 12:48 AM David Feuer <david.feuer at gmail.com> wrote:

> 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
> https://stackoverflow.com/questions/6463058/help-on-writing-the-colist-monad-exercise-from-an-idioms-intro-paper
> by pigworker (Conor McBride) and C. A. McCann.
>
> On Thu, Jun 4, 2020, 2:53 AM Dannyu NDos <ndospark320 at gmail.com> wrote:
>
>> instance Monad ZipList where
>>     ZipList [] >>= _ = ZipList []
>>     ZipList (x:xs) >>= f = ZipList $ do
>>         let ZipList y' = f x
>>         guard (not (null y'))
>>         let ZipList ys = ZipList xs >>= ZipList . join . maybeToList .
>> fmap snd . uncons . getZipList . f
>>         head y' : ys
>>
>> instance MonadFail ZipList where
>>     fail _ = empty
>>
>> instance MonadPlus ZipList
>> _______________________________________________
>> Libraries mailing list
>> Libraries at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20200604/f4950d0a/attachment.html>


More information about the Libraries mailing list