[Haskell-cafe] A small oversight

Holger Siegel holgersiegel74 at yahoo.de
Sat Feb 20 05:53:49 EST 2010

Am Samstag, den 20.02.2010, 10:47 +0000 schrieb Andrew Coppin:
> I just discovered the highly useful function Data.Function.on. I vaguely 
> recall a few people muttering a couple of years back that this would be 
> a useful thing to have, but I had no idea it was in the standard 
> libraries now.
> Anyway, while using it, I discovered a small omission from the Haskell 
> libraries: We have min, max, minimum and maximum. We also have minimumBy 
> and maximumBy. But there's no sign of minBy or maxBy. You can do, for 
> example,
>   (min `on` postcode) customer1 customer2
> but that gives you the lowest postcode, not the customer to which this 
> postcode belongs. By contrast,
>   minimumBy (compare `on` postcode) [customer1, customer2]
> gives you the corresponding customer. But it seems silly to have to 
> actually construct a list just for this. So... is there any danger of 
> getting minBy and maxBy added? (I don't actually know off the top of my 
> head where min and max are defined - the Prelude?)

minBy and maxBy are already defined in Data.List - but they are local to
minimumBy and maximumBy.

More information about the Haskell-Cafe mailing list