patternMinor
Each element is the sum of itself with the next element of a List: now do this point-free in Haskell
Viewed 0 times
itselfthistheeachpointwithfreenextnowelement
Problem
Here it is the best I can do (I am a noob using Haskell):
I'm looking for a point-free solution.
map (\(y, z) -> y + z) (zip x (tail x))I'm looking for a point-free solution.
Solution
Pointfree, eh? Let's ask lambdabot.
Assuming that
Personally I'd go with the former; I'm not a fan of Lambdabot's gratuitous use of
@pl map (\(y, z) -> y + z) (zip x (tail x))
zipWith (+) x (tail x)Assuming that
x is simply the input to this "function" @pl \x -> map (\(y, z) -> y + z) (zip x (tail x))
map (uncurry (+)) . ap zip tailPersonally I'd go with the former; I'm not a fan of Lambdabot's gratuitous use of
uncurry and ap.Code Snippets
<DanBurton> @pl map (\(y, z) -> y + z) (zip x (tail x))
<lambdabot> zipWith (+) x (tail x)<DanBurton> @pl \x -> map (\(y, z) -> y + z) (zip x (tail x))
<lambdabot> map (uncurry (+)) . ap zip tailContext
StackExchange Code Review Q#6299, answer score: 7
Revisions (0)
No revisions yet.