
On 2/28/12 1:25 PM, Brent Yorgey wrote:
On Tue, Feb 28, 2012 at 06:06:25PM +0100, Johan Holmquist wrote:
inter :: (a -> a -> b) -> [a] -> [b] inter f [] = [] inter f l = map (uncurry f) $ zip l (tail l)
I've never seen this function defined anywhere, but it looks nice.
I've used it a few times, but never seen it defined in libraries. Of course, you can simplify the implementation by: inter f xs = zipWith f xs (tail xs)
withPair :: (a' -> b' -> c) -> (a -> a') -> (b -> b') -> (a,b) -> c withPair f fa fb (a,b) = fa a `f` fb b
Note that
withPair f g h === uncurry f . (g *** h)
Also: import Data.Function.Pointless -- from pointless-fun withPair f g h = uncurry (f $:: g ~> h ~> id) which is certainly no shorter since pointless-fun doesn't handle tuples directly like the arrow combinators do, but it does generalize much further. Though I can't say as I've used the withPair idiom very often, despite using (***) and friends quite regularly... -- Live well, ~wren