Advertisement
Guest User

Untitled

a guest
May 16th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   // replace calls of returned functions by .apply for clarity
  2.   // these are our calls to g
  3.   foldLeftViaFoldRight(List(1,2), 0)(f)
  4.  
  5.   foldRight(List(1,2), b => b)((a,g) => b => g(f(b, a)))(0)
  6.   (b1 => foldRight(List(2), b => b)((a,g) => b => g(f(b, a))).apply(f(b1, 1)))(0) // (1)
  7.  
  8.   // look at inner fold right separately:
  9.   foldRight(List(2), b => b)((a,g) => b => g(f(b, a)))
  10.   b2 => foldRight(Nil, b => b)((a,g) => b => g(f(b, a))).apply(f(b2, 2))
  11.   b2 => (b => b).apply(f(b2, 2)) // we reach zero element, identity
  12.   b2 => f(b2, 2))
  13.  
  14.   // insert into (1)
  15.   (b1 => (b2 => f(b2, 2)).apply(f(b1, 1)))(0)
  16.   (b2 => f(b2, 2)).apply(f(0, 1))) // apply the function from foldRight to zero value
  17.   f(f(0, 1), 2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement