
At 11:58 AM -0700 4/2/06, Jared Updike wrote:
Is there a common way (standard libs, higher order) to express the lambda part below? It's not particulary complicated but I think it is not higher-order enough
unionBy (\x y -> fst x == fst y) listOfPairs1 listOfPairs2
Something like "distribute fst (==)" where
distribute f op x y = f x `op` f y
would leave
unionBy (distribute fst (==)) listOfPairs1 listOfPairs2
I imagine something involving Arrows and/or zip/curry/uncurry but I just can't see it. Is this a case of trying to make something more complicated than it is?
Jared.
I think you've reached sufficient higher-order-ness. Others on the list have offered your function in a slightly different form:
f `on` g = \x y -> g x `f` g y unionBy ((==) `on` fst) listOfPairs1 listOfPairs2