[Haskell-cafe] Is this haskelly enough?
shachaf at gmail.com
Tue Jul 17 19:17:24 EDT 2007
> on, which will appear in Data.Function in the next release of base,
> is defined thusly:
> on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
> (*) `on` f = \x y -> f x * f y
You can also use Data.Ord.comparing, in this case -- comparing is just
-- > comparing p x y = compare (p x) (p y)
-- Useful combinator for use in conjunction with the @xxxBy@ family
-- of functions from "Data.List", for example:
-- > ... sortBy (comparing fst) ...
comparing :: (Ord a) => (b -> a) -> b -> b -> Ordering
comparing p x y = compare (p x) (p y)
More information about the Haskell-Cafe