I’ve read through some of the post on here about closures and currying but I feel like I didn’t find the answer. So what’s the differences and possibly the similarities of closures and currying? Thanks for the help 🙂
Share
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.
Currying is really a mathematical concept first and foremost. It’s the just observation that for any n-ary function f: S0×…Sn → R, you can define a new function fprime (just found a markdown bug!) with n-1 parameters where that first parameter is replaced by a constant. So, if you have a function
add(a,b), you can define a new functionadd1(b)asadd1(b) ::= add(1, b)…reading ‘::=’ as ‘is defined to be.’
A closure is more of a programming concept. (Of course, everything in programming is a mathematical concept as well, but closures became interesting because of programming.) When you construct a closure, you bind one or more variables; you’re creating a chunk of code that has some variables tied to it.
The relationship is that you can use a closure in order to implement currying: you could build your
add1function above by making a closure in which that first parameter is bound to 1.