
Here's my thoughts on why it's impossible:
ZipList is basically ReaderT Natural Maybe with the requirement that
f m === Nothing -> forall n > m. f n === Nothing
The Applicative and Alternative instances are derived straightforwardly in
this manner and satisfy the requirements, but there is no way to verify the
requirement for the Monad instance. I'm pretty sure that this:
ZipList [0..] >>= (\n -> if even n then pure (div n 2) else empty)
would produce nonsense no matter the definition of (>>=).
On Thu, Jun 4, 2020, 10:57 David Feuer
To add documentation, we need an explanation of *why* it's impossible.
On Thu, Jun 4, 2020, 11:35 AM chessai .
wrote: Agreed, that would be a great addition.
On Thu, Jun 4, 2020, 8:31 AM Simon Jakobi
wrote: This sounds worth documenting though.
Dannyu, would you be interested in updating the ZipList docs to say why it doesn't have a Monad instance?
Cheers, Simon
Am Do., 4. Juni 2020 um 17:21 Uhr schrieb chessai . < chessai1996@gmail.com>:
David is right. This can't happen, unfortunately
On Thu, Jun 4, 2020, 12:48 AM David Feuer
I don't remember why right now, but it's moderately well-known that
wrote: 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... by pigworker (Conor McBride) and C. A. McCann.
On Thu, Jun 4, 2020, 2:53 AM Dannyu NDos
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@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
_______________________________________________ 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