
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
participants (1)
-
Oleg Grenrus