ApplicativeZip
Oleg Grenrus
oleg.grenrus at iki.fi
Sun Mar 8 18:17:14 UTC 2015
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 <david.feuer at gmail.com> wrote:
>
> It was already discussed, I think, but I don't remember the conclusion!
>
> On Mar 6, 2015 3:27 AM, "Oleg Grenrus" <oleg.grenrus at iki.fi> 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 at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
-------------- 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/20150308/9cfd9bb8/attachment.sig>
More information about the Libraries
mailing list