ApplicativeZip

Oleg Grenrus oleg.grenrus at iki.fi
Fri Mar 6 08:27:32 UTC 2015


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20150306/b42f75dd/attachment.sig>


More information about the Libraries mailing list