<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>With [], Maybe, and some other Alternative Functors, we have the nice property that empty <*> x = empty. (Think near-semiring.)<br><br>But with your lifted version, empty <*> Compose empty = Compose empty. The authentically empty 'empty' is still the true zero element.<br><br>-Keith<br>—<br>Sent from my phone with K-9 Mail.<br><br><div class="gmail_quote">On July 16, 2020 2:00:22 AM UTC, Asad Saeeduddin <masaeedu@gmail.com> wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<p>Hello folks,<br>
<br>
base 4.14 has the following instance for `Compose f g`:<br>
<br>
</p>
<pre>instance (Alternative f, Applicative g) => Alternative (Compose f g) where
empty = Compose empty
(<|>) = coerce ((<|>) :: f (g a) -> f (g a) -> f (g a))
:: forall a . Compose f g a -> Compose f g a -> Compose f g a
</pre>
This instance doesn't really do anything with the `Applicative g`
constraint it is demanding. It's also kind of unclear what utility
it delivers, given that the resulting Alternative instance is
indistinguishable from the outer functor's Alternative instance. In
other words: `getCompose $ Compose x <|> Compose y == x
<|> y`.<br>
<br>
It seems to me a more useful instance would be:<br>
<br>
<pre>instance (Applicative f, Alternative g) => Alternative (Compose f g) where
empty = Compose $ pure empty
(<|>) = _ $ liftA2 (<|>)
</pre>
This is also nicer in a mathematical sense: `Applicative` functors
correspond to lax monoidal functors from `Hask, (- , -), ()` to
`Hask, (-, -), ()`. We can interpret `Alternative`s as lax monoidal
functors from `Hask, Either - -, Void` to `Hask, (-, -), ()`.
Compatible lax monoidal functors compose, but if you think about the
relevant "types" of the functors a bit, you'll realize that while we
can compose an `Applicative` after an `Alternative` to get another
`Alternative`, the reverse does not work. Hence the instance we have
today, which has no choice but to just ignore the `Applicative`
constraint it is demanding.<br>
<br>
Does it make sense to replace the instance we have today with the
`pure empty`, `liftA2 (<|>)` one?<br>
<br>
Thanks,<br>
Asad<br>
</blockquote></div></body></html>