<p dir="ltr">Eq instances should only be used for conceptual equality, and never just for convenience applying some function or other. I don't think that makes any sort of argument for "equating", though.</p>

<div class="gmail_quote">On Jul 20, 2014 8:46 PM, "John Lato" <<a href="mailto:jwlato@gmail.com">jwlato@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">The utility of the proposed "equating" extends far beyond simply using it with groupBy.  Just last week I used "on (==)" as part of a complicated boolean expression.<br><div><br></div><div>

That said, I just want to be clear that I'm understanding Greg properly.  Are you advocating that one should generally create a newtype+Eq instance rather than using "on (==)"?  What is the benefit of this approach?  The only one I can think of is that it makes the standard libraries smaller, which seems like a rather small gain considering that you've changed a 7-character expression into multi-line boilerplate for everyone, hampering readability in the process.  Is there something I'm missing here?</div>

<div><br></div><div>(Currently +0 on the proposal)</div><div><br></div><div>John L.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jul 21, 2014 at 8:27 AM, Greg Weber <span dir="ltr"><<a href="mailto:greg@gregweber.info" target="_blank">greg@gregweber.info</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"><div>I am -1 on things that encourage converting Eq to Bool rather than just using Eq directly.</div><div>

<br></div>Is there a use case for group that is not satisfied by groupOn with a newtype with an Eq instance?<div>

Granted, a newtype may be heavy-weight, but I feel that the current group should be an escape hatch in the rare case that groupOn does not suffice, not something we codify via <span style="font-family:arial,sans-serif;font-size:12.800000190734863px">Fairbairn threshold because that is the only API that exists today. I can create a separate proposal for adding groupOn, etc.</span></div>



</div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jul 18, 2014 at 12:57 PM, Greg Weber <span dir="ltr"><<a href="mailto:greg@gregweber.info" target="_blank">greg@gregweber.info</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">I think the `By` functions that expect a Bool are all cumbersome because they are too flexible. 100% of the time I personally use these functions I want to use Ord or Eq.<div>



What I would like to see is a function groupOn next to groupBy.</div>
<div><br></div><div>groupOn :: Eq b => (a -> b) -> [a] -> [[a]]</div><div><br></div><div>Then equating is no longer needed, and one just writes: groupOn snd</div><div>I believe this style also gives better opportunity for optimization (Scwartzian transform).</div>




<div><br></div><div>Of course, this function is still problematic because it operates only on lists and does not group over the entire list, but those are separate issues.</div><div>All of this is solved in mono-traversable right now by the groupAllOn function [1]</div>




<div><br></div><div>[1] <a href="http://hackage.haskell.org/package/mono-traversable-0.6.0.4/docs/Data-Sequences.html" target="_blank">http://hackage.haskell.org/package/mono-traversable-0.6.0.4/docs/Data-Sequences.html</a></div>



</div><div><div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Fri, Jul 18, 2014 at 12:26 PM, Frerich Raabe <span dir="ltr"><<a href="mailto:raabe@froglogic.com" target="_blank">raabe@froglogic.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




Hi,<br>
<br>
A common use case for 'on' (from Data.Function) is to use it with 'compare', e.g. 'compare `on` snd'. In fact, this pattern is so common that there's a convenient 'comparing' function which provides a shortcut for this use case such that one can write<br>





<br>
  sortBy (comparing snd)<br>
<br>
instead of<br>
<br>
  sortBy (compare `on` snd)<br>
<br>
I think another common use case is to use 'on' together with (==) as in<br>
<br>
  groupBy ((==) `on` snd)<br>
<br>
In a similiar vein as with 'comparing', I think it would be nice if there was a function which encapsulates this use case, like<br>
<br>
  equating :: Eq b => (a -> b) -> a -> a -> Bool<br>
  equating = on (==)<br>
<br>
such that one can write<br>
<br>
  groupBy (equating snd)<br>
<br>
In fact, groupBy is just one of many *By functions taking an a -> a -> Bool -- many of which are Data.List, e.g. groupBy, nubBy, deleteBy, intersectBy, unionBy. Hence, it seems plausible to define 'equating' in Data.List. This is the same reasoning as why 'comparing' is in Data.Ord: because the module exposes a lot of *By functions taking an a -> a -> Ordering.<br>





<br>
- Frerich<br>
<br>
______________________________<u></u>_________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/libraries" target="_blank">http://www.haskell.org/<u></u>mailman/listinfo/libraries</a><br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/libraries" target="_blank">http://www.haskell.org/mailman/listinfo/libraries</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/libraries" target="_blank">http://www.haskell.org/mailman/listinfo/libraries</a><br>
<br></blockquote></div>