# Each element is the sum of itself with the next element of a List: now do this point-free in Haskell

Here it is the best I can do (I am a noob using Haskell):

map (\(y, z) -> y + z) (zip x (tail x))


I'm looking for a point-free solution.

• "Each element is the sum of itself with the next element of a List", so in other words, repeat 0? :) – Dan Burton Nov 26 '11 at 19:57

<DanBurton> @pl map (\(y, z) -> y + z) (zip x (tail x))
<lambdabot> zipWith (+) x (tail x)


Assuming that x is simply the input to this "function"

<DanBurton> @pl \x -> map (\(y, z) -> y + z) (zip x (tail x))
<lambdabot> map (uncurry (+)) . ap zip tail


Personally I'd go with the former; I'm not a fan of Lambdabot's gratuitous use of uncurry and ap.

• The fact that Haskell has an IRC bot that can refactor Haskell code blows my mind. Well played sir. – Daniel Huckstep Dec 10 '11 at 4:50
• The usage of lambdabot here is amazing. I would give you 10 ups, if I could! – Hugo Sereno Ferreira Apr 2 '12 at 12:07

You could use &&& from Control.Arrow (along with the zipWith trick from Dan's solution):

foo = uncurry (zipWith (+)) . (tail &&& id)