DEV Community

What is Currying?

Namc on February 25, 2018

Original article published at : https://namc.in/2018-02-22-currying Inspiration This post is written after I saw a tweet which read ...
Collapse
 
gefjon profile image
Phoebe Goldman

I'm unclear on the Lisp snippet you give in the paragraph starting "If you are familiar with other languages..." It looks based on context ("Java's f(a, b, c)") like you're trying to show calling the function f with the arguments a, b and c, which would traditionally look like

(f a b c)

Your existing Lisp snippet, (((f a) b) c) is how one would call a curried function of 3 arguments in Lisp, which translates to Java as f(a)(b)(c) (I think. Does Java even do anonymous functions? That's how it would look in C++, Javascript, etc., at least).

Collapse
 
artus_lla profile image
Arturo Llaja Alarcón

Great article.

On the function:
curry f n = \m -> f n m

g = curry (+) 5

g 10 -- returns 15

h = curry (*) 5

g 10 -- returns 50

The last line should be:

h 10 -- returns 50

Collapse
 
flexdinesh profile image
Dinesh Pandiyan

Can someone make a Javascript version of this? I've been trying to find a convincing example and explanation of currying for a while now.

Collapse
 
krumpez profile image
Amine

what a way to program !!