Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between f(a,b) and f(a)(b) in Scala

Tags:

scala

I am very very new to Scala. I am reading a book called functional programming in scala by Paul Chiusano and Rúnar Bjarnason. So far I am finding it interesting. I see a solution for curry and uncurry

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

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

In Curry I understand f(a,b) which results in value of type C but in uncurry I do not understand f(a)(b). Can anyone please tell me how to read f(a)(b) or how is this resulting to a type of C or please refer me some online material that can explain this to me?

Thanks for your help.

like image 468
Hari Rao Avatar asked Dec 04 '25 21:12

Hari Rao


1 Answers

Basically the return type of f(a) is a function of type B => C lets call this result g. If you then call g(b) you obtain a value of type C. f(a)(b) can be expanded to f.apply(a).apply(b)

like image 81
J. Fraudeau Avatar answered Dec 06 '25 11:12

J. Fraudeau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!