Generalise type of deleteBy

The type of `deleteBy` in `Data.List` could easily be generalised in a useful way. ``` deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a] ``` to ``` deleteBy :: (a -> b -> Bool) -> a -> [b] -> [b] ``` There is this closed ticket but no reasons for not generalising. https://ghc.haskell.org/trac/ghc/ticket/3399 Discussion Period: 1 week. Matt

On Sun, Sep 11, 2016 at 1:25 PM, Matthew Pickering < matthewtpickering@gmail.com> wrote:
The type of `deleteBy` in `Data.List` could easily be generalised in a useful way.
``` deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a] ```
to
``` deleteBy :: (a -> b -> Bool) -> a -> [b] -> [b] ```
There is this closed ticket but no reasons for not generalising.
https://ghc.haskell.org/trac/ghc/ticket/3399
Discussion Period: 1 week.
Matt _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
+1, seems straightforward. My only concern: does anyone have real life examples of code where this generalization would lead to type inference problems? I can't think of anything offhand. Michael

I have no objection.
+1
-Edward
On Sun, Sep 11, 2016 at 6:28 AM, Michael Snoyman
On Sun, Sep 11, 2016 at 1:25 PM, Matthew Pickering < matthewtpickering@gmail.com> wrote:
The type of `deleteBy` in `Data.List` could easily be generalised in a useful way.
``` deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a] ```
to
``` deleteBy :: (a -> b -> Bool) -> a -> [b] -> [b] ```
There is this closed ticket but no reasons for not generalising.
https://ghc.haskell.org/trac/ghc/ticket/3399
Discussion Period: 1 week.
Matt _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
+1, seems straightforward. My only concern: does anyone have real life examples of code where this generalization would lead to type inference problems? I can't think of anything offhand.
Michael
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

I put a patch up on phab with the suggested changes. It also seemed
sensible to generalise deleteFirstsBy.
https://phabricator.haskell.org/D2526
Matt
On Sun, Sep 11, 2016 at 1:33 PM, Edward Kmett
I have no objection.
+1
-Edward
On Sun, Sep 11, 2016 at 6:28 AM, Michael Snoyman
wrote: On Sun, Sep 11, 2016 at 1:25 PM, Matthew Pickering
wrote: The type of `deleteBy` in `Data.List` could easily be generalised in a useful way.
``` deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a] ```
to
``` deleteBy :: (a -> b -> Bool) -> a -> [b] -> [b] ```
There is this closed ticket but no reasons for not generalising.
https://ghc.haskell.org/trac/ghc/ticket/3399
Discussion Period: 1 week.
Matt _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
+1, seems straightforward. My only concern: does anyone have real life examples of code where this generalization would lead to type inference problems? I can't think of anything offhand.
Michael
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

On Sun, 11 Sep 2016, Matthew Pickering wrote:
The type of `deleteBy` in `Data.List` could easily be generalised in a useful way.
``` deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a] ```
I do not see why deleteBy should have an argument for the deleted element, anyway, since it is not even the element to delete (only an equivalent one). Wouldn't a function with type newDeleteBy :: (a -> Bool) -> [a] -> [a] be much more straight-forward?

Going with Henning's newDeleteBy would provide a better interface to deleting with an arbitrary predicate, and it would avoid the (unlikely?) chance of code breaking in the event that the more general type breaks some type inference. On Sun, Sep 11, 2016, 9:19 AM Henning Thielemann < lemming@henning-thielemann.de> wrote:
On Sun, 11 Sep 2016, Matthew Pickering wrote:
The type of `deleteBy` in `Data.List` could easily be generalised in a useful way.
``` deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a] ```
I do not see why deleteBy should have an argument for the deleted element, anyway, since it is not even the element to delete (only an equivalent one). Wouldn't a function with type
newDeleteBy :: (a -> Bool) -> [a] -> [a]
be much more straight-forward? _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

I have to admit I've always found the need to pass an argument to deleteBy
sort of silly. The few times I've used it, my function has just ignored the
first argument. I don't think we need to worry too much about inference in
this case, the user would almost assuredly pick it back up on the backswing
from whatever (a -> a -> Bool) predicate they are using fixing the type
anyways.
I don't find the two proposals mutually exclusive.
-Edward
On Sun, Sep 11, 2016 at 1:00 PM, Eric Mertens
Going with Henning's newDeleteBy would provide a better interface to deleting with an arbitrary predicate, and it would avoid the (unlikely?) chance of code breaking in the event that the more general type breaks some type inference.
On Sun, Sep 11, 2016, 9:19 AM Henning Thielemann < lemming@henning-thielemann.de> wrote:
On Sun, 11 Sep 2016, Matthew Pickering wrote:
The type of `deleteBy` in `Data.List` could easily be generalised in a useful way.
``` deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a] ```
I do not see why deleteBy should have an argument for the deleted element, anyway, since it is not even the element to delete (only an equivalent one). Wouldn't a function with type
newDeleteBy :: (a -> Bool) -> [a] -> [a]
be much more straight-forward? _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

On 11 Sep 2016, at 17:19, Henning Thielemann wrote:
I do not see why deleteBy should have an argument for the deleted element, anyway, since it is not even the element to delete (only an equivalent one). Wouldn't a function with type
newDeleteBy :: (a -> Bool) -> [a] -> [a]
be much more straight-forward?
It already exists, and is called "filter", modulo the sense of the boolean. Regards, Malcolm

Malcolm, the semantics of deleteBy are slightly different as it only
deletes the first occurrence. In the end however I did use `filter` as
I didn't
care particularly about just deleting the first matching value, as
there was at most one matching value in the whole list.
Joachim, it seems to me that `deleteBy` is the odd one out as the
types of `sortBy` and `maximumBy` are the most general types.
Anyway, this function is not used very often. I searched on hackage
and there were less than 50 uses. There is a simple patch which I have
provided and people are welcome to merge if they like but I don't
think we should spend a lot of time arguing about this or worrying
about potential breakage.
Matt
On Mon, Sep 12, 2016 at 9:53 AM, Malcolm Wallace
On 11 Sep 2016, at 17:19, Henning Thielemann wrote:
I do not see why deleteBy should have an argument for the deleted element, anyway, since it is not even the element to delete (only an equivalent one). Wouldn't a function with type
newDeleteBy :: (a -> Bool) -> [a] -> [a]
be much more straight-forward?
It already exists, and is called "filter", modulo the sense of the boolean.
Regards, Malcolm
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

Hi, Am Sonntag, den 11.09.2016, 11:25 +0100 schrieb Matthew Pickering:
deleteBy :: (a -> b -> Bool) -> a -> [b] -> [b]
-1 from me. This makes this different from the usual fooBy pattern, and the fact this this is possible points to some code smell, namely the lack of a (a -> Bool) -> [a] -> [a] function. Greetings, Joachim -- Joachim “nomeata” Breitner mail@joachim-breitner.de • https://www.joachim-breitner.de/ XMPP: nomeata@joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org

-1 from me as well, for the same reasons.
On Sep 11, 2016 8:11 PM, "Joachim Breitner"
Hi,
Am Sonntag, den 11.09.2016, 11:25 +0100 schrieb Matthew Pickering:
deleteBy :: (a -> b -> Bool) -> a -> [b] -> [b]
-1 from me. This makes this different from the usual fooBy pattern, and the fact this this is possible points to some code smell, namely the lack of a
(a -> Bool) -> [a] -> [a]
function.
Greetings, Joachim
-- Joachim “nomeata” Breitner mail@joachim-breitner.de • https://www.joachim-breitner.de/ XMPP: nomeata@joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

On Sun, Sep 11, 2016 at 5:11 PM, Joachim Breitner
Hi,
Am Sonntag, den 11.09.2016, 11:25 +0100 schrieb Matthew Pickering:
deleteBy :: (a -> b -> Bool) -> a -> [b] -> [b]
-1 from me. This makes this different from the usual fooBy pattern, and the fact this this is possible points to some code smell, namely the lack of a
(a -> Bool) -> [a] -> [a]
function.
I agree. I'd much rather see the (a->Bool)->[a]->[a] function as the proper generalization of delete. As far as bikeshedding goes, something like "deleteFirst" would make it clearer how it differs from filter as well as avoiding issues with the fooBy naming convention (though I see there's a deleteFirstsBy which probably ruins our chances of using this name). -- Live well, ~wren
participants (10)
-
David Feuer
-
Edward Kmett
-
Eric Mertens
-
Henning Thielemann
-
Joachim Breitner
-
John Wiegley
-
Malcolm Wallace
-
Matthew Pickering
-
Michael Snoyman
-
wren romano