
After thinking for a while (and looking onto MonadZip [] instance), I realised that: `MonadZip []` is the same as `Applicative ZIpList`, not `Applicative []` I guess that answers my question. Also Information preservation law: liftM (const ()) ma = liftM (const ()) mb excludes the default implementation of munzip for non-deterministic computations, as the information is “multiplied". The naturality law follows from Applicative laws. — After some thinking (and re-reading the "Monadic zipping (used for monad comprehensions)” comment in the documentation), this is obvious. But I’ll try to make a documentation improvement patch, so no-one have to wonder this that much again. - Oleg
On 06 Mar 2015, at 10:30, David Feuer
wrote: It was already discussed, I think, but I don't remember the conclusion!
On Mar 6, 2015 3:27 AM, "Oleg Grenrus"
wrote: After Edward Kmett mentioned that we should add MonadZip to Data.Monoid instances, that got me thinking about: Why we don’t have ApplicativeZip?
class Applicative f => ApplicativeZip f where {-# MINIMAL azip | azipWith #-} azip :: m a -> m b -> m (a,b) azip = azipWith (,)
-- This is `liftA2` but can be done more efficiently for some instances (is it true?) azipWith :: (a -> b -> c) -> m a -> m b -> m c azipWith f = azip (uncurry f)
aunzip :: m (a,b) -> (m a, m b) aunzip mab = (fst <$> mab, liftM <$> mab)
and
class (Monad m, ApplicativeZip m) => MonadZip m where mzip :: m a -> m b -> m (a,b) mzip = azip
mzipWith :: (a -> b -> c) -> m a -> m b -> m c mzipWith = azipWith
munzip :: m (a,b) -> (m a, m b) munzip = aunzip
IMHO that should been done during AMP-reform, sorry if this topic is already discussed.
- Oleg
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries