0

I would like to rewrite

foldr (\_ y = y + 1) 0

using flip, const and (+1) and function composition.

I've gotten this far:

foldr (\x -> ((+1) . (flip const x)) 0

But I can't seem to ditch this lambda. Is there any way to do so?

hgiesel
  • 5,430
  • 2
  • 29
  • 56

1 Answers1

6

Note that (\_ -> e) = const e, and here e = (\y -> y + 1) = (+1). Therefore,

foldr (const (+1)) 0
Li-yao Xia
  • 31,896
  • 2
  • 33
  • 56