Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // replace calls of returned functions by .apply for clarity
- // these are our calls to g
- foldLeftViaFoldRight(List(1,2), 0)(f)
- foldRight(List(1,2), b => b)((a,g) => b => g(f(b, a)))(0)
- (b1 => foldRight(List(2), b => b)((a,g) => b => g(f(b, a))).apply(f(b1, 1)))(0) // (1)
- // look at inner fold right separately:
- foldRight(List(2), b => b)((a,g) => b => g(f(b, a)))
- b2 => foldRight(Nil, b => b)((a,g) => b => g(f(b, a))).apply(f(b2, 2))
- b2 => (b => b).apply(f(b2, 2)) // we reach zero element, identity
- b2 => f(b2, 2))
- // insert into (1)
- (b1 => (b2 => f(b2, 2)).apply(f(b1, 1)))(0)
- (b2 => f(b2, 2)).apply(f(0, 1))) // apply the function from foldRight to zero value
- f(f(0, 1), 2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement