Code mistake (5.2)
Closed this issue · 0 comments
kosgdk commented
5.2 Functions and 5.2.3.1 A Better Abstraction:
def abstraction(end: Int, f: ???): Int =
this match {
case End => end
case Pair(hd, tl) => f(hd, tl.abstraction(f, end)) //Mistake
}
tl.abstraction(f, end)
parameters should be swapped: tl.abstraction(end, f)
C.4.6 Solution to: A Better Abstraction:
def fold(end: Int, f: (Int, Int) => Int): Int =
this match {
case End => end
case Pair(hd, tl) => f(hd, tl.fold(f, end)) //Mistake
}
tl.fold(f, end)
parameters should be swapped: tl.fold(end, f)