Proposal: add 'equating' function to Data.List

John Lato jwlato at gmail.com
Mon Jul 21 01:53:37 UTC 2014


On Mon, Jul 21, 2014 at 9:38 AM, Greg Weber <greg at gregweber.info> wrote:

>
> On Sun, Jul 20, 2014 at 5:46 PM, John Lato <jwlato at gmail.com> wrote:
>
>> 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.
>>
>> 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?
>>
>
> Sorry I didn't do a good job explaining. groupOn takes a function that is
> a projection to an equality instance (Eq b => (a -> b)).
> So there is no need for a newtype, and this interface has suited 100% of
> my needs, and every usage I have ever seen in Haskell code.
>
> My presumption is that the only reason this interface is not 100%
> satisfactory and we have this weird interface based on Bool is because you
> may want to compare something that does not have an Eq instance. One could
> still handle that case by wrapping the projected value in a newtype and
> writing an Eq instance for that newtype.
>

I see, thanks for the explanation.  Seems like a reasonable function IMHO.

It still isn't a full replacement for equating though.  In my case, I used
"if on (==) someLongSelector a b then ..." to save some characters over the
obvious alternative.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20140721/3578ab25/attachment.html>


More information about the Libraries mailing list