Why does `mzip /= liftM2 (,)`

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Why does `mzip /= liftM2 (,)`

Mateusz Kowalczyk
Hi,

Today after half a decade I have found `MonadZip` in `base`.

The laws state:

```
liftM (f *** g) (mzip ma mb) = mzip (liftM f ma) (liftM g mb)


liftM (const ()) ma = liftM (const ()) mb
==>
munzip (mzip ma mb) = (ma, mb)
```

The question is why does

```
mzip /= liftM2 (,)
```

in plain words. Notably we can see lack of IO instance which I'm
guessing has something to do asynchronous exceptions but I'm probably
wrong…. Rather than investigating for next 30 minutes, I thought I'd
just sample existing knowledge (that I could not find out from Google).

In what circumstances can we not replace `liftM2 (,)` with `mzip`?

--
Mateusz K.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Why does `mzip /= liftM2 (,)`

MarLinn

> The question is why does
>
> ```
> mzip /= liftM2 (,)
>
> ```

I don't have any evidence, but my gut feeling is that indeed mzip ==
liftM2 (,) == liftA2 (,), but that MonadZip just predates many advances,
and that it's not used often enough to warrant changing. Especially
because changing stuff in base comes with huge costs and long debates.

Today I would expect something similar to look somewhat more like this:

```
class Applicative f => Unzippative f where
     unzipF :: f (a,b) => (f a, f b)
```

I personally can't remember a single time that function would have come
in handy, so I'm happy with Applicative. And I'm projecting that
experience onto others and drawing the conclusion of "Meh.".

But if you find out more after
> investigating for next 30 minutes

I'd be interested to hear. ;)

Cheers,
MarLinn
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Why does `mzip /= liftM2 (,)`

Theodore Lief Gannon
What about:

bisequence :: (Functor f, Bifunctor g) => f (g a b) -> g (f a) (f b)

On Apr 20, 2017 12:21 PM, "MarLinn" <[hidden email]> wrote:

The question is why does

```
mzip /= liftM2 (,)

```

I don't have any evidence, but my gut feeling is that indeed mzip == liftM2 (,) == liftA2 (,), but that MonadZip just predates many advances, and that it's not used often enough to warrant changing. Especially because changing stuff in base comes with huge costs and long debates.

Today I would expect something similar to look somewhat more like this:

```
class Applicative f => Unzippative f where
    unzipF :: f (a,b) => (f a, f b)
```

I personally can't remember a single time that function would have come in handy, so I'm happy with Applicative. And I'm projecting that experience onto others and drawing the conclusion of "Meh.".

But if you find out more after
investigating for next 30 minutes

I'd be interested to hear. ;)

Cheers,
MarLinn
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Why does `mzip /= liftM2 (,)`

Mateusz Kowalczyk
In reply to this post by MarLinn
On 04/20/2017 08:19 PM, MarLinn wrote:

>
>> The question is why does
>>
>> ```
>> mzip /= liftM2 (,)
>>
>> ```
>
> I don't have any evidence, but my gut feeling is that indeed mzip ==
> liftM2 (,) == liftA2 (,), but that MonadZip just predates many advances,
> and that it's not used often enough to warrant changing. Especially
> because changing stuff in base comes with huge costs and long debates.

Normally I would agree but in case of adding instances, there are no
real costs or long debates. Indeed to add a lawful instance you could
just send a diff to GHC and see it in next version. In my experience
there are only arguments where there are multiple possible "reasonable"
instances &c. Hence my question in this case.

Even if it was legacy, IO was around in 2011 and there seems to be no
reason why it wouldn't have been one of the default instances.

> Today I would expect something similar to look somewhat more like this:
>
> ```
> class Applicative f => Unzippative f where
>      unzipF :: f (a,b) => (f a, f b)
> ```
>
> I personally can't remember a single time that function would have come
> in handy, so I'm happy with Applicative. And I'm projecting that
> experience onto others and drawing the conclusion of "Meh.".
>

I think we have a bunch across projects.

> But if you find out more after
>> investigating for next 30 minutes
>
> I'd be interested to hear. ;)

Me too! Maybe on weekend if there are no good replies.

> Cheers,
> MarLinn
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
>


--
Mateusz K.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Why does `mzip /= liftM2 (,)`

Dmitry Olshansky
Instances for MonadZip not always defined as "liftM2 (,)".

Compare:

> liftM2 (,) (Alt [1..2]) (Alt ("foo"))
Alt {getAlt = [(1,'f'),(1,'o'),(1,'o'),(2,'f'),(2,'o'),(2,'o')]}

> mzip (Alt [1..2]) (Alt ("foo"))
Alt {getAlt = [(1,'f'),(2,'o')]}


2017-04-20 23:07 GMT+03:00 Mateusz Kowalczyk <[hidden email]>:
On 04/20/2017 08:19 PM, MarLinn wrote:
>
>> The question is why does
>>
>> ```
>> mzip /= liftM2 (,)
>>
>> ```
>
> I don't have any evidence, but my gut feeling is that indeed mzip ==
> liftM2 (,) == liftA2 (,), but that MonadZip just predates many advances,
> and that it's not used often enough to warrant changing. Especially
> because changing stuff in base comes with huge costs and long debates.

Normally I would agree but in case of adding instances, there are no
real costs or long debates. Indeed to add a lawful instance you could
just send a diff to GHC and see it in next version. In my experience
there are only arguments where there are multiple possible "reasonable"
instances &c. Hence my question in this case.

Even if it was legacy, IO was around in 2011 and there seems to be no
reason why it wouldn't have been one of the default instances.

> Today I would expect something similar to look somewhat more like this:
>
> ```
> class Applicative f => Unzippative f where
>      unzipF :: f (a,b) => (f a, f b)
> ```
>
> I personally can't remember a single time that function would have come
> in handy, so I'm happy with Applicative. And I'm projecting that
> experience onto others and drawing the conclusion of "Meh.".
>

I think we have a bunch across projects.

> But if you find out more after
>> investigating for next 30 minutes
>
> I'd be interested to hear. ;)

Me too! Maybe on weekend if there are no good replies.

> Cheers,
> MarLinn
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
>


--
Mateusz K.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.


_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Loading...