2.3

Let’s look at another example, currying,9 which converts a function f of two arguments into a function of one argument that partially applies f. Here again there’s only one implementation that compiles. Write this implementation. def curryA,B,C => C): A => (B => C)

Solution

object Main {
    def curry[A,B,C](f: (A, B) => C): A => (B => C) = {
        a => b => f(a,b)
    }

    def main(args: Array[String]) = {
        val c = curry((a:Int, b:Int) => a == b)
        println("1 == 2? ", c(1)(2))
        println("2 == 2? ", c(2)(2))

        val c_partial = c(1)

        println("[partial] 1 == 2? ", c_partial(2))
        println("[partial] 1 == 1? ", c_partial(1))
    }
}