Hi.
 
Can you describe a problem whose solution becomes much easier by using
currying?
 
----->Nathan


________________________________

        From: jquery-en@googlegroups.com
[mailto:[EMAIL PROTECTED] On Behalf Of Sean Catchpole
        Sent: Monday, April 16, 2007 8:17 PM
        To: jquery-en@googlegroups.com
        Subject: [jQuery] Re: Library showdowns
        
        
        Jeffrey and Glen,
        
        Allow me to explain currying. Imagine if you will the following
function (written in javascript)
        add = function (a,b) { return a+b }
        I can now call add(3,7) and it will return 10.
        A language that allows currying would allow me to pass only one
variable and it would return a new function that takes a single
variable. ex: add(3) would return a function that adds three to the
input. Here is an example way of implementing it in javascript:
        add = function (a) { return function (b) { return a+b } }
        Now I can call add(3) and it will return function (b) { return
3+b } 
        In the same sense as the first example we can now call add(3)(7)
and it will return 10.
        
        This allows for lots of cleverness in use of functions and
ultimately make functions far more reusable. I consider it a great
advantage of functional programming. So as you can see, the same effect
can be created, but it's tedious. I'm trying to come up with a trickier
way so that it's not so painful to create a curried function in
javascript. 
        
        
        ~Sean 

Reply via email to