<div dir="ltr">The usual intuition behind the list Functor/Applicative/Monad instances are that they represents non-deterministic values, which can have any of some list of possible values.  In this case, the natural interpretation of <|> is as a non-deterministic choice of two possible computations.  So the list of possible results would include anything from either computation.  Your implementation, on the other hand, would represent a left-biased choice, where the right alternative is only used if the left is impossible.<div><br></div><div>It's hard to look at laws, because there's apparently little agreement on the proper laws for Alternative.  It looks possible that as an Applicative and Alternative, this would be fine; but the Alternative instance you propose would work in odd ways with the Monad instance.  That is, if f x == [] for any x in (non-empty) xs, then something like (xs <|> ys) >>= f would yield an empty list, while (xs >>= f) <|> (ys >>= f) would not.  But, this isn't a law or anything, you could chalk it up as counter-intuitive, but not disqualifying.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 5, 2017 at 11:12 PM, Theodore Lief Gannon <span dir="ltr"><<a href="mailto:tanuki@gmail.com" target="_blank">tanuki@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Fiddling around, I found myself wanting:<div><br></div><div><font face="monospace, monospace">coalesce :: [a] -> [a] -> [a]</font></div><div><font face="monospace, monospace">-- or -- :: (Foldable t) => t a -> t a -> t a</font></div><div><font face="monospace, monospace">coalesce a b = if null a then b else a</font></div><div><br></div><div>I expected this to be <font face="monospace, monospace">(<|>)</font><font face="arial, helvetica, sans-serif"> (it is for </font><font face="monospace, monospace">Maybe</font><font face="arial, helvetica, sans-serif">!) </font>but instead I find no canonical implementation of it anywhere, and what seems like a useless <font face="monospace, monospace">instance Alternative []</font>. What's the rationale?</div></div>
<br>______________________________<wbr>_________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/haskell-<wbr>cafe</a><br>
Only members subscribed via the mailman list are allowed to post.<br></blockquote></div><br></div>