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.
Pointfree, eh? Let's ask lambdabot.
<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
.
You could use &&&
from Control.Arrow
(along with the zipWith
trick from Dan's solution):
foo = uncurry (zipWith (+)) . (tail &&& id)
repeat 0
? :) \$\endgroup\$