Anyone have a decent example, preferably practical/useful, they could post demonstrating the concept?
Anyone have a decent example, preferably practical/useful, they could post demonstrating the concept?
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.
My examples will cover using it for the reuse and encapsulation of code. This is fairly obvious once you look at these and should give you a concrete, simple example that you can think of applying in numerous situations.
We want to do a map over a tree. This function could be curried and applied to each node if it needs more then one argument — since we’d be applying the one at the node as it’s final argument. It doesn’t have to be curried, but writing another function (assuming this function is being used in other instances with other variables) would be a waste.
but this is the same as:
So this simple case isn’t convincing. It really is though, and powerful once you use the language more and naturally come across these situations. The other example with some code reuse as currying. A recurrence relation to create prime numbers. Awful lot of similarity in there:
Ok, now rowland and cloitre are curried functions, since they have free variables, and we can get any index of it’s sequence without knowing or worrying about f_recurrence.