What is meaning of this function signature?


#1

In functional programming, what does this signature means:

def partial1[A,B,C](a: A, f: (A,B) => C): B => C

What I understand is that ‘partial1’ takes an argument of type A, and a function which takes arguments of type A and B, and returns type C.

But what does ‘B => C’ implies here?


#2

It means partial1 returns a function that takes a B and returns a C. It implies that partial1 partially applies the function f with argument a.


#3

Actually, there is only one pure function def f[A,B,C](a: A, ab2c: (A,B) => C): B => C for all A, B and C. Try thinking of another one, you will need some specific knowledge of A, B or C to define it.


#4

The signature as a whole means, 'If you give me an A, then if you give me a function which can get a C from an A and a B, then I can give you back a function which can get a C from a B'.

Note that I can’t give you back a C directly because I don’t have enough information; I am missing one piece of information, that is a B. So, I can invert the dependency: I can give you back a recipe for getting a C, but only if you supply the B.

Does that make sense?