What does it mean when someone says “functions in scala associate to the right“?
And, how will associativity work in case Int => Int => Int
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The function type
Int => Int => Intis equivalent toInt => (Int => Int). In other words, the=>groups things on the right first, or, is right-associative.The type
Int => (Int => Int)defines a single-argument function that accepts anIntand whose return-type is function fromInttoInt.So what’s an example of such a function? We could write a function called
sumwith this type:So
sumtakes an argumentaand returns a new function that accepts and argumentband returns the sum ofaandb: