what is the difference between currying and partial application

14 comments

@Jon Skeet 2008-10-20 11:02:06

Interesting question. After a bit of searching, "Partial Function Application is not currying" gave the best explanation I found. I can't say that the practical difference is particularly obvious to me, but then I'm not an FP expert...

Currying is to do with tuples (turning a function that takes a tuple argument into one that takes n separate arguments, and vice versa). Partial application is the ability to apply a function to some arguments, yielding a new function for the remaining arguments. It is easy to remember if you just think currying == to do with tuples.

@Zaheer Ahmed 2014-10-28 07:29:06

@Jon links you posted are informative, but it will be better to expand your answer and add some more info here.

@Jon Skeet 2014-10-28 08:06:57

@Zaheer: This answer is over 6 years old, and the other answers already cover it. I don't think there's much to be gained from expanding this now.

Can't believe you got 20 upvotes for a couple links and an admission you don't really know the difference between curry and partial application. Well played, sir.

@Ogen 2018-11-02 03:26:30

Someone's mad they're not Jon Skeet

@Brennan Cheung 2019-05-12 19:11:29

I'm going to assume most people who ask this question are already familiar with the basic concepts so their is no need to talk about that. It's the overlap that is the confusing part.

You might be able to fully use the concepts, but you understand them together as this pseudo-atomic amorphous conceptual blur. What is missing is knowing where the boundary between them is.

Instead of defining what each one is, it's easier to highlight just their differences—the boundary.

Currying is when you define the function.

Partial Application is when you call the function.

Application is math-speak for calling a function.

Partial application requires calling a curried function and getting a function as the return type.

@Mark Cidade 2008-10-20 11:02:57

Currying is converting a single function of n arguments into n functions with a single argument each. Given the following function:

In order to get the full application of f(x,y,z), you need to do this:

f(x)(y)(z);

Many functional languages let you write f x y z. If you only call f x y or f(x)(y) then you get a partially-applied function—the return value is a closure of lambda(z){z(x(y))} with passed-in the values of x and y to f(x,y).

One way to use partial application is to define functions as partial applications of generalized functions, like fold:

function fold(combineFunction, accumulator, list) {/* ... */}
function sum = curry(fold)(lambda(accum,e){e+accum}))(0);
function length = curry(fold)(lambda(accum,_){1+accum})(empty-list);
function reverse = curry(fold)(lambda(accum,e){concat(e,accum)})(empty-list);
/* ... */
@list = [1, 2, 3, 4]
sum(list) //returns 10
@f = fold(lambda(accum,e){e+accum}) //f = lambda(accumulator,list) {/*...*/}
f(0,list) //returns 10
@g = f(0) //same as sum
g(list) //returns 10

@SpoonMeiser 2008-10-20 11:22:25

You're saying that partial application is when you curry a function, and use some, but not all of the resulting functions?

@Mark Cidade 2008-10-20 11:27:53

more or less, yes. If you only supply a subset of the arguments, you'll get back a function that accepts the rest of the arguments

@SpoonMeiser 2008-10-20 11:34:59

Would changing a function f(a, b, c, d) to g(a, b) count as partial application? Or is it only when applied to curried functions? Sorry to be a pain, but I'm angling for an explicit answer here.

@Mark Cidade 2008-10-20 11:42:25

g(a,b) would be a partial application only if g == f(a,b) and g(a',b') == f(a,b,a',b'). Partial application has to go in the order the arguments are specified

@SpoonMeiser 2008-10-20 13:14:17

But the same is not true for currying? I could translate f(a, b, c) into g(c) -> h(a) -> i(b), and that would still be currying? And then I couldn't use these functions for partial application?

@Mark Cidade 2008-10-20 17:18:08

If you re-arranged the arguments like that, I guess it can still be considered currying. You can then go ahead and call g(x) and get back a function that accepts "a" and then "b" as arguments. Or call "g(c)(a)" and get back a function that accepts "b".

@Jason Bunting 2010-07-21 23:25:35

Anent your statement: Currying is converting a single function of n arguments into n functions with a single argument each - I understand just the opposite; currying is taking multiple, one-argument functions, then composing a multiple-argument function. Whereas a partially applied function is creating from a function that accepts multiple arguments a function that requires fewer, e.g. var Add = function(a,b) { return a + b; } var AddOne = partial(Add, 1); Can you cite sources for your explanation/understanding? Here is one I read: bit.ly/CurryingVersusPartialApplication

@Mark Cidade 2010-07-24 23:17:53

@Jason: Your source says the same thing that I do—in its example, it takes a pre-curried multi-argument function defined using "define/curried" and re-composes it back uisng partial application. For a clearer definition of currying and partial application that are the same as mine, see en.wikipedia.org/wiki/Currying .

@Jason Bunting 2010-08-09 18:13:48

@Mark: I guess this is just one of those concepts that brings out the pedant in me - but an appeal to authoritative sources does little to satisfy, since they all seem to point to one another. Wikipedia is hardly what I consider an authoritative source, but I understand that it's hard to find much else. Suffice it to say that I think we both know that of which we speak and the power thereof, regardless of whether or not we can agree (or disagree) on the particulars of the vernacular! :) Thanks Mark!

@Ustaman Sangat 2011-09-19 21:17:28

In Haskell, in the following two: map (^2) [ 1..3] ==> [1, 4, 9] AND map (2^) [1..3] ==> [2, 4, 8] I can see how (2^) is ((^) 2), but how about (^2)? To achieve something similar with a "prefix" function, would I have to do: mod 3 and "e;mod"e; 3 respectively?

@Pacerier 2014-05-02 23:43:08

@JasonBunting, Regarding your first comment, what you were talking about is decurrying. Currying is taking a multi-arg function as input and returning a chain of 1-arg functions as output. De-currying is taking a chain of 1-arg functions as input and returning a multi-arg function as output. As elaborated on stackoverflow.com/a/23438430/632951

@Roland 2017-08-30 07:52:22

Currying is a function of one argument which takes a function f and returns a new function h. Note that h takes an argument from X and returns a function that maps Y to Z:

curry(f) = h
f: (X x Y) -> Z
h: X -> (Y -> Z)

Partial application is a function of two(or more) arguments which takes a function f and one or more additional arguments to f and returns a new function g:

part(f, 2) = g
f: (X x Y) -> Z
g: Y -> Z

The confusion arises because with a two-argument function the following equality holds:

partial(f, a) = curry(f)(a)

Both sides will yield the same one-argument function.

The equality is not true for higher arity functions because in this case currying will return a one-argument function, whereas partial application will return a multiple-argument function.

The difference is also in the behavior, whereas currying transforms the whole original function recursively(once for each argument), partial application is just a one step replacement.

Curry: lets you call a function, splitting it in multiple calls, providing one argument per-call.

Partial: lets you call a function, splitting it in multiple calls, providing multiple arguments per-call.

Simple hints

Both allow you to call a function providing less arguments (or, better, providing them cumulatively). Actually both of them bind (at each call) a specific value to specific arguments of the function.

The real difference can be seen when the function has more than 2 arguments.

Simple e(c)(sample)

(in Javascript)

function process(context, success_callback, error_callback, subject) {...}

why always passing the arguments, like context and the callbacks, if they will be always the same? Just bind some values for the the function

With currying you'd need to pass one argument per time

curriedProcess = _.curry(process);
processWithBoundedContext = curriedProcess(my_context);
processWithCallbacks = processWithBoundedContext(my_success)(my_error); // note: these are two sequential calls
result1 = processWithCallbacks('subject1');
// same as: process(my_context, my_success, my_error, 'subject1');
result2 = processWithCallbacks('foobar');
// same as: process(my_context, my_success, my_error, 'foobar');

Disclaimer

I skipped all the academic/mathematical explanation. Cause I don't know it. Maybe it helped 🙃

@sunny-mittal 2017-11-13 02:30:17

I had this question a lot while learning and have since been asked it many times. The simplest way I can describe the difference is that both are the same :) Let me explain...there are obviously differences.

Both partial application and currying involve supplying arguments to a function, perhaps not all at once. A fairly canonical example is adding two numbers. In pseudocode (actually JS without keywords), the base function may be the following:

add = (x, y) => x + y

If I wanted an "addOne" function, I could partially apply it or curry it:

addOneC = curry(add, 1)
addOneP = partial(add, 1)

Now using them is clear:

addOneC(2) #=> 3
addOneP(2) #=> 3

So what's the difference? Well, it's subtle, but partial application involves supplying some arguments and the returned function will then execute the main function upon next invocation whereas currying will keep waiting till it has all the arguments necessary:

curriedAdd = curry(add) # notice, no args are provided
addOne = curriedAdd(1) # returns a function that can be used to provide the last argument
addOne(2) #=> returns 3, as we want
partialAdd = partial(add) # no args provided, but this still returns a function
addOne = partialAdd(1) # oops! can only use a partially applied function once, so now we're trying to add one to an undefined value (no second argument), and we get an error

In short, use partial application to prefill some values, knowing that the next time you call the method, it will execute, leaving undefined all unprovided arguments; use currying when you want to continually return a partially-applied function as many times as necessary to fulfill the function signature. One final contrived example:

curriedAdd = curry(add)
curriedAdd()()()()()(1)(2) # ugly and dumb, but it works
partialAdd = partial(add)
partialAdd()()()()()(1)(2) # second invocation of those 7 calls fires it off with undefined parameters

Hope this helps!

UPDATE: Some languages or lib implementations will allow you to pass an arity (total number of arguments in final evaluation) to the partial application implementation which may conflate my two descriptions into a confusing mess...but at that point, the two techniques are largely interchangeable.

@Sled 2017-02-27 21:19:31

There are other great answers here but I believe this example (as per my understanding) in Java might be of benefit to some people:

public static <A,B,X> Function< B, X > partiallyApply( BiFunction< A, B, X > aBiFunction, A aValue ){
return b -> aBiFunction.apply( aValue, b );
}
public static <A,X> Supplier< X > partiallyApply( Function< A, X > aFunction, A aValue ){
return () -> aFunction.apply( aValue );
}
public static <A,B,X> Function< A, Function< B, X > > curry( BiFunction< A, B, X > bif ){
return a -> partiallyApply( bif, a );
}

So currying gives you a one-argument function to create functions, where partial-application creates a wrapper function that hard codes one or more arguments.

If you want to copy&paste, the following is noisier but friendlier to work with since the types are more lenient:

public static <A,B,X> Function< ? super B, ? extends X > partiallyApply( final BiFunction< ? super A, ? super B, X > aBiFunction, final A aValue ){
return b -> aBiFunction.apply( aValue, b );
}
public static <A,X> Supplier< ? extends X > partiallyApply( final Function< ? super A, X > aFunction, final A aValue ){
return () -> aFunction.apply( aValue );
}
public static <A,B,X> Function< ? super A, Function< ? super B, ? extends X > > curry( final BiFunction< ? super A, ? super B, ? extends X > bif ){
return a -> partiallyApply( bif, a );
}

@Roland 2017-08-30 06:34:51

The following gave me the key insight: "So currying gives you a one-argument function to create functions, where partial-application creates a wrapper function that hard codes one or more arguments."

@sunny-mittal 2015-12-07 05:00:23

I could be very wrong here, as I don't have a strong background in theoretical mathematics or functional programming, but from my brief foray into FP, it seems that currying tends to turn a function of N arguments into N functions of one argument, whereas partial application [in practice] works better with variadic functions with an indeterminate number of arguments. I know some of the examples in previous answers defy this explanation, but it has helped me the most to separate the concepts. Consider this example (written in CoffeeScript for succinctness, my apologies if it confuses further, but please ask for clarification, if needed):

# partial application
partial_apply = (func) ->
args = [].slice.call arguments, 1
-> func.apply null, args.concat [].slice.call arguments
sum_variadic = -> [].reduce.call arguments, (acc, num) -> acc + num
add_to_7_and_5 = partial_apply sum_variadic, 7, 5
add_to_7_and_5 10 # returns 22
add_to_7_and_5 10, 11, 12 # returns 45
# currying
curry = (func) ->
num_args = func.length
helper = (prev) ->
->
args = prev.concat [].slice.call arguments
return if args.length < num_args then helper args else func.apply null, args
helper []
sum_of_three = (x, y, z) -> x + y + z
curried_sum_of_three = curry sum_of_three
curried_sum_of_three 4 # returns a function expecting more arguments
curried_sum_of_three(4)(5) # still returns a function expecting more arguments
curried_sum_of_three(4)(5)(6) # returns 15
curried_sum_of_three 4, 5, 6 # returns 15

This is obviously a contrived example, but notice that partially applying a function that accepts any number of arguments allows us to execute a function but with some preliminary data. Currying a function is similar but allows us to execute an N-parameter function in pieces until, but only until, all N parameters are accounted for.

Again, this is my take from things I've read. If anyone disagrees, I would appreciate a comment as to why rather than an immediate downvote. Also, if the CoffeeScript is difficult to read, please visit coffeescript.org, click "try coffeescript" and paste in my code to see the compiled version, which may (hopefully) make more sense. Thanks!

@Pacerier 2014-05-02 23:26:31

The easiest way to see how they differ is to consider a real example. Let's assume that we have a function Add which takes 2 numbers as input and returns a number as output, e.g. Add(7, 5) returns 12. In this case:

Partial applying the function Add with a value 7 will give us a new function as output. That function itself takes 1 number as input and outputs a number. As such:

Partial(Add, 7); // returns a function f2 as output
// f2 takes 1 number as input and returns a number as output

So we can do this:

f2 = Partial(Add, 7);
f2(5); // returns 12;
// f2(7)(5) is just a syntactic shortcut

Currying the function Add will give us a new function as output. That function itself takes 1 number as input and outputs yet another new function. That third function then takes 1 number as input and returns a number as output. As such:

Curry(Add); // returns a function f2 as output
// f2 takes 1 number as input and returns a function f3 as output
// i.e. f2(number) = f3
// f3 takes 1 number as input and returns a number as output
// i.e. f3(number) = number

So we can do this:

f2 = Curry(Add);
f3 = f2(7);
f3(5); // returns 12

In other words, "currying" and "partial application" are two totally different functions. Currying takes exactly 1 input, whereas partial application takes 2 (or more) inputs.

Even though they both return a function as output, the returned functions are of totally different forms as demonstrated above.

@bob 2016-03-10 16:01:29

Partial application transforms a function from n-ary to (x - n)-ary, currying from n-ary to n * 1-ary. A partially applied function has a reduced scope (of application), that is, Add7 is less expressive than Add. A curried function on the other hand is as expressive as the original function.

@Maksim Gumerov 2017-02-08 09:40:04

I believe the more distinctive trait is when we curry f(x,y,z)=>R, we get f(x) which returns g(y)=>h(z)=>R, each consuming a single argument; but when we partially apply f(x,y,z) as f(x) we get g(y,z)=>R, that is, with two arguments. If not for that trait, we could say that currying is like partial application to 0 arguments, thus leaving all arguments unbound; however in reality f() partially applied to 0 arguments is a function consuming 3 args at once, unlike curried f().

@fnl 2017-07-15 08:06:31

Once again the correct answer isn't the first or the most voted: The simple explanation of the signature of curry vs. partial at the end of this answer is really the easiest way to resolve the question.

@Zach Mierzejewski 2018-08-22 14:44:23

What does the comment f2(7)(5) is just a syntactic shortcut mean? (I know very little.) Doesn't f2 already contain/"know about" 7?

@alancalvitti 2019-05-03 14:11:03

@Pacerier, is there a curry implementation somewhere (don't think it's in functools)

@Prof Mo 2019-06-19 01:06:05

I am having a hard time with curry vs partial because in functional language, such as OCaml, there is no difference between currying and partial application. This holds because in functional languages, functions are first-class objects.

@nomen 2014-04-09 03:29:17

In writing this, I confused currying and uncurrying. They are inverse transformations on functions. It really doesn't matter what you call which, as long as you get what the transformation and its inverse represent.

Uncurrying isn't defined very clearly (or rather, there are "conflicting" definitions that all capture the spirit of the idea). Basically, it means turning a function that takes multiple arguments into a function that takes a single argument. For example,

(+) :: Int -> Int -> Int

Now, how do you turn this into a function that takes a single argument? You cheat, of course!

plus :: (Int, Int) -> Int

Notice that plus now takes a single argument (that is composed of two things). Super!

What's the point of this? Well, if you have a function that takes two arguments, and you have a pair of arguments, it is nice to know that you can apply the function to the arguments, and still get what you expect. And, in fact, the plumbing to do it already exists, so that you don't have to do things like explicit pattern matching. All you have to do is:

(uncurry (+)) (1,2)

So what is partial function application? It is a different way to turn a function in two arguments into a function with one argument. It works differently though. Again, let's take (+) as an example. How might we turn it into a function that takes a single Int as an argument? We cheat!

((+) 0) :: Int -> Int

That's the function that adds zero to any Int.

((+) 1) :: Int -> Int

adds 1 to any Int. Etc. In each of these cases, (+) is "partially applied".

@gsklee 2013-05-27 03:51:08

The difference between curry and partial application can be best illustrated through this following JavaScript example:

function f(x, y, z) {
return x + y + z;
}
var partial = f.bind(null, 1);
6 === partial(2, 3);

Partial application results in a function of smaller arity; in the example above, f has an arity of 3 while partial only has an arity of 2. More importantly, a partially applied function would return the result right away upon being invoke, not another function down the currying chain. So if you are seeing something like partial(2)(3), it's not partial application in actuality.

" a partially applied function would return the result right away upon being invoke" - that's not correct, is it? when I partially apply a function, that expression returns a function, not "a result". Ok, you probably meant that this latter function, when called with the remaining arguments, returns the result, unlike digging one step down into currying. But no one actually says you have to specify all the remaining arguments: you can partially-apply the result of partial application, and that will once again be a function, not a "result"

@Taoufik Dachraoui 2013-05-13 10:03:40

For me partial application must create a new function where the used arguments are completely integrated into the resulting function.

Most functional languages implement currying by returning a closure: do not evaluate under lambda when partially applied. So, for partial application to be interesting, we need to make a difference between currying and partial application and consider partial application as currying plus evaluation under lambda.

@Ji Han 2012-10-11 19:40:41

I have answered this in another thread https://stackoverflow.com/a/12846865/1685865 . In short, partial function application is about fixing some arguments of a given multivariable function to yield another function with fewer arguments, while Currying is about turning a function of N arguments into a unary function which returns a unary function...[An example of Currying is shown at the end of this post.]

Currying is mostly of theoretical interest: one can express computations using only unary functions (i.e. every function is unary). In practice and as a byproduct, it is a technique which can make many useful (but not all) partial functional applications trivial, if the language has curried functions. Again, it is not the only means to implement partial applications. So you could encounter scenarios where partial application is done in other way, but people are mistaking it as Currying.

(Example of Currying)

In practice one would not just write

lambda x: lambda y: lambda z: x + y + z

or the equivalent javascript

function (x) { return function (y){ return function (z){ return x + y + z }}}

instead of

lambda x, y, z: x + y + z

for the sake of Currying.

@SpoonMeiser 2012-11-07 11:16:29

Would you say that currying is a specific case of partial application then?

@Pacerier 2014-05-02 23:32:14

@SpoonMeiser, No, currying is not a specific case of partial application: A partial application of a 2-input function is not the same as currying the function. See stackoverflow.com/a/23438430/632951 .

@dodgy_coder 2012-05-04 05:18:33

Note: this was taken from F# Basics an excellent introductory article for .NET developers getting into functional programming.

Currying means breaking a function with many arguments into a series
of functions that each take one argument and ultimately produce the
same result as the original function. Currying is probably the most
challenging topic for developers new to functional programming, particularly because it
is often confused with partial application. You can see both at work
in this example:

let multiply x y = x * y
let double = multiply 2
let ten = double 5

Right away, you should see behavior that is different from most
imperative languages. The second statement creates a new function
called double by passing one argument to a function that takes two.
The result is a function that accepts one int argument and yields the
same output as if you had called multiply with x equal to 2 and y
equal to that argument. In terms of behavior, it’s the same as this
code:

let double2 z = multiply 2 z

Often, people mistakenly say that multiply is curried to form double.
But this is only somewhat true. The multiply function is curried, but
that happens when it is defined because functions in F# are curried by
default. When the double function is created, it’s more accurate to
say that the multiply function is partially applied.

The multiply function is really a series of two functions. The first
function takes one int argument and returns another function,
effectively binding x to a specific value. This function also accepts
an int argument that you can think of as the value to bind to y. After
calling this second function, x and y are both bound, so the result is
the product of x and y as defined in the body of double.

To create double, the first function in the chain of multiply
functions is evaluated to partially apply multiply. The resulting
function is given the name double. When double is evaluated, it uses
its argument along with the partially applied value to create the
result.

## 14 comments

## @Jon Skeet 2008-10-20 11:02:06

Interesting question. After a bit of searching, "Partial Function Application is not currying" gave the best explanation I found. I can't say that the

practicaldifference is particularly obvious to me, but then I'm not an FP expert...Another useful-looking page (which I confess I haven't fully read yet) is "Currying and Partial Application with Java Closures".

It does look like this is widely-confused pair of terms, mind you.

## @SpoonMeiser 2008-10-20 11:13:14

Interesting links, although they do offer conflicting ideas of what currying is.

## @Jason Bunting 2010-07-21 23:27:11

The first link is spot-on about the differences. Here's another one I found useful: bit.ly/CurryingVersusPartialApplication

## @Don Stewart 2012-09-11 11:38:20

Currying is to do with tuples (turning a function that takes a tuple argument into one that takes n separate arguments, and vice versa). Partial application is the ability to apply a function to some arguments, yielding a new function for the remaining arguments. It is easy to remember if you just think currying == to do with tuples.

## @Zaheer Ahmed 2014-10-28 07:29:06

@Jon links you posted are informative, but it will be better to expand your answer and add some more info here.

## @Jon Skeet 2014-10-28 08:06:57

@Zaheer: This answer is over 6 years old, and the other answers already cover it. I don't think there's much to be gained from expanding this now.

## @user247702 2014-10-28 08:08:39

@Jon see meta.stackoverflow.com/questions/275464/…

## @Jon Skeet 2014-10-28 08:10:06

@Stijn: Thanks for the context.

## @AlienWebguy 2015-07-06 18:37:36

Can't believe you got 20 upvotes for a couple links and an admission you don't really know the difference between curry and partial application. Well played, sir.

## @Ogen 2018-11-02 03:26:30

Someone's mad they're not Jon Skeet

## @Brennan Cheung 2019-05-12 19:11:29

I'm going to assume most people who ask this question are already familiar with the basic concepts so their is no need to talk about that. It's the overlap that is the confusing part.

You might be able to fully use the concepts, but you understand them together as this pseudo-atomic amorphous conceptual blur. What is missing is knowing where the boundary between them is.

Instead of defining what each one is, it's easier to highlight just their differences—the boundary.

Curryingis when youdefinethe function.Partial Applicationis when youcallthe function.Applicationis math-speak for calling a function.Partialapplication requires calling a curried function and getting a function as the return type.## @Mark Cidade 2008-10-20 11:02:57

Currying is converting a single function of

narguments intonfunctions with a single argument each. Given the following function:When curried, becomes:

In order to get the full application of f(x,y,z), you need to do this:

Many functional languages let you write

`f x y z`

. If you only call`f x y`

orf(x)(y)then you get a partially-applied function—the return value is a closure of`lambda(z){z(x(y))}`

with passed-in the values of x and y to`f(x,y)`

.One way to use partial application is to define functions as partial applications of generalized functions, like

fold:## @SpoonMeiser 2008-10-20 11:22:25

You're saying that partial application is when you curry a function, and use some, but not all of the resulting functions?

## @Mark Cidade 2008-10-20 11:27:53

more or less, yes. If you only supply a subset of the arguments, you'll get back a function that accepts the rest of the arguments

## @SpoonMeiser 2008-10-20 11:34:59

Would changing a function f(a, b, c, d) to g(a, b) count as partial application? Or is it only when applied to curried functions? Sorry to be a pain, but I'm angling for an explicit answer here.

## @Mark Cidade 2008-10-20 11:42:25

g(a,b) would be a partial application only if g == f(a,b) and g(a',b') == f(a,b,a',b'). Partial application has to go in the order the arguments are specified

## @SpoonMeiser 2008-10-20 13:14:17

But the same is not true for currying? I could translate f(a, b, c) into g(c) -> h(a) -> i(b), and that would still be currying? And then I couldn't use these functions for partial application?

## @Mark Cidade 2008-10-20 17:18:08

If you re-arranged the arguments like that, I guess it can still be considered currying. You can then go ahead and call g(x) and get back a function that accepts "a" and then "b" as arguments. Or call "g(c)(a)" and get back a function that accepts "b".

## @Jason Bunting 2010-07-21 23:25:35

Anent your statement:

Currying is converting a single function of n arguments into n functions with a single argument each- I understand just the opposite; currying is taking multiple, one-argument functions, thencomposinga multiple-argument function. Whereas a partially applied function is creating from a function that accepts multiple arguments a function that requires fewer, e.g.`var Add = function(a,b) { return a + b; } var AddOne = partial(Add, 1);`

Can you cite sources for your explanation/understanding? Here is one I read: bit.ly/CurryingVersusPartialApplication## @Mark Cidade 2010-07-24 23:17:53

@Jason: Your source says the same thing that I do—in its example, it takes a pre-curried multi-argument function defined using "define/curried" and re-composes it back uisng partial application. For a clearer definition of currying and partial application that are the same as mine, see en.wikipedia.org/wiki/Currying .

## @Jason Bunting 2010-08-09 18:13:48

@Mark: I guess this is just one of those concepts that brings out the pedant in me - but an appeal to authoritative sources does little to satisfy, since they all seem to point to one another. Wikipedia is hardly what I consider an authoritative source, but I understand that it's hard to find much else. Suffice it to say that I think we both know that of which we speak and the power thereof, regardless of whether or not we can agree (or disagree) on the particulars of the vernacular! :) Thanks Mark!

## @Ustaman Sangat 2011-09-19 21:17:28

In Haskell, in the following two:

`map (^2) [ 1..3]`

==> [1, 4, 9] AND map`(2^) [1..3]`

==> [2, 4, 8] I can see how`(2^)`

is`((^) 2)`

, but how about`(^2)`

? To achieve something similar with a "prefix" function, would I have to do:`mod 3`

and`"e;mod"e; 3`

respectively?## @Pacerier 2014-05-02 23:43:08

@JasonBunting, Regarding your first comment, what you were talking about is

decurrying. Currying is taking a multi-arg function as input and returning a chain of 1-arg functions as output. De-currying is taking a chain of 1-arg functions as input and returning a multi-arg function as output. As elaborated on stackoverflow.com/a/23438430/632951## @Roland 2017-08-30 07:52:22

Currying is a function of

oneargument which takes a function`f`

and returns a new function`h`

. Note that`h`

takes an argument from`X`

and returns afunctionthat maps`Y`

to`Z`

:Partial application is a function of

two(or more)arguments which takes a function`f`

and one or more additional arguments to`f`

and returns a new function`g`

:The confusion arises because with a two-argument function the following equality holds:

Both sides will yield the same one-argument function.

The equality is not true for higher arity functions because in this case currying will return a one-argument function, whereas partial application will return a multiple-argument function.

The difference is also in the behavior, whereas currying transforms the whole original function recursively(once for each argument), partial application is just a one step replacement.

Source: Wikipedia Currying.

## @Kamafeather 2018-07-09 20:13:38

## Simple answer

Curry:lets you call a function, splitting it in multiple calls, providing one argument per-call.Partial:lets you call a function, splitting it in multiple calls, providing multiple arguments per-call.## Simple hints

Both allow you to call a function providing less arguments (or, better, providing them cumulatively). Actually both of them bind (at each call) a specific value to specific arguments of the function.

The real difference can be seen when the function has more than 2 arguments.

## Simple e(c)(sample)

(in Javascript)why always passing the arguments, like context and the callbacks, if they will be always the same? Just bind some values for the the function

and call it on

subject1andfoobarwithComfy, isn't it? 😉

With

curryingyou'd need to pass one argument per time## Disclaimer

I skipped all the academic/mathematical explanation. Cause I don't know it. Maybe it helped 🙃

## @sunny-mittal 2017-11-13 02:30:17

I had this question a lot while learning and have since been asked it many times. The simplest way I can describe the difference is that both are the same :) Let me explain...there are obviously differences.

Both partial application and currying involve supplying arguments to a function, perhaps not all at once. A fairly canonical example is adding two numbers. In pseudocode (actually JS without keywords), the base function may be the following:

If I wanted an "addOne" function, I could partially apply it or curry it:

Now using them is clear:

So what's the difference? Well, it's subtle, but partial application involves supplying some arguments and the returned function will then

execute the main function upon next invocationwhereas currying will keep waiting till it has all the arguments necessary:In short, use partial application to prefill some values, knowing that the next time you call the method, it will execute, leaving undefined all unprovided arguments; use currying when you want to continually return a partially-applied function as many times as necessary to fulfill the function signature. One final contrived example:

Hope this helps!

UPDATE: Some languages or lib implementations will allow you to pass an arity (total number of arguments in final evaluation) to the partial application implementation which may conflate my two descriptions into a confusing mess...but at that point, the two techniques are largely interchangeable.

## @Sled 2017-02-27 21:19:31

There are other great answers here but I believe this example (as per my understanding) in Java might be of benefit to some people:

So currying gives you a one-argument function to create functions, where partial-application creates a wrapper function that hard codes one or more arguments.If you want to copy&paste, the following is noisier but friendlier to work with since the types are more lenient:

## @Roland 2017-08-30 06:34:51

The following gave me the key insight: "So currying gives you a one-argument function to create functions, where partial-application creates a wrapper function that hard codes one or more arguments."

## @sunny-mittal 2015-12-07 05:00:23

I could be very wrong here, as I don't have a strong background in theoretical mathematics or functional programming, but from my brief foray into FP, it seems that currying tends to turn a function of N arguments into N functions of one argument, whereas partial application [in practice] works better with variadic functions with an indeterminate number of arguments. I know some of the examples in previous answers defy this explanation, but it has helped me the most to separate the concepts. Consider this example (written in CoffeeScript for succinctness, my apologies if it confuses further, but please ask for clarification, if needed):

This is obviously a contrived example, but notice that partially applying a function that accepts any number of arguments allows us to execute a function but with some preliminary data. Currying a function is similar but allows us to execute an N-parameter function in pieces until, but only until, all N parameters are accounted for.

Again, this is my take from things I've read. If anyone disagrees, I would appreciate a comment as to why rather than an immediate downvote. Also, if the CoffeeScript is difficult to read, please visit coffeescript.org, click "try coffeescript" and paste in my code to see the compiled version, which may (hopefully) make more sense. Thanks!

## @Pacerier 2014-05-02 23:26:31

The easiest way to see how they differ is to consider a

real example. Let's assume that we have a function`Add`

which takes 2 numbers as input and returns a number as output, e.g.`Add(7, 5)`

returns`12`

. In this case:Partial applyingthe function`Add`

with a value`7`

will give us a new function as output. That function itself takes 1 number as input and outputs a number. As such:So we can do this:

Curryingthe function`Add`

will give us a new function as output. That function itself takes 1 number as input and outputsyetanother new function. That third function then takes 1 number as input and returns a number as output. As such:So we can do this:

In other words, "currying" and "partial application" are two totally different functions.

Currying takes exactly 1 input, whereas partial application takes 2 (or more) inputs.Even though they both return a function as output, the returned functions are of totally different forms as demonstrated above.

## @bob 2016-03-10 16:01:29

Partial application transforms a function from

`n-ary`

to`(x - n)-ary`

, currying from`n-ary`

to`n * 1-ary`

. A partially applied function has areduced scope(of application), that is,`Add7`

is less expressive than`Add`

. A curried function on the other hand is as expressive as the original function.## @Maksim Gumerov 2017-02-08 09:40:04

I believe the more distinctive trait is when we curry f(x,y,z)=>R, we get f(x) which returns g(y)=>h(z)=>R, each consuming a single argument; but when we partially apply f(x,y,z) as f(x) we get g(y,z)=>R, that is, with two arguments. If not for that trait, we could say that currying is like partial application to 0 arguments, thus leaving all arguments unbound; however in reality f() partially applied to 0 arguments is a function consuming 3 args at once, unlike curried f().

## @fnl 2017-07-15 08:06:31

Once again the correct answer isn't the first or the most voted: The simple explanation of the signature of curry vs. partial at the end of this answer is really the easiest way to resolve the question.

## @Zach Mierzejewski 2018-08-22 14:44:23

What does the comment

`f2(7)(5) is just a syntactic shortcut`

mean? (I know very little.) Doesn't`f2`

already contain/"know about" 7?## @alancalvitti 2019-05-03 14:11:03

@Pacerier, is there a

`curry`

implementation somewhere (don't think it's in`functools`

)## @Prof Mo 2019-06-19 01:06:05

I am having a hard time with curry vs partial because in functional language, such as OCaml, there is no difference between currying and partial application. This holds because in functional languages, functions are first-class objects.

## @nomen 2014-04-09 03:29:17

In writing this, I confused currying and uncurrying. They are inverse transformations on functions. It really doesn't matter what you call which, as long as you get what the transformation and its inverse represent.

Uncurrying isn't defined very clearly (or rather, there are "conflicting" definitions that all capture the spirit of the idea). Basically, it means turning a function that takes multiple arguments into a function that takes a single argument. For example,

Now, how do you turn this into a function that takes a single argument? You cheat, of course!

Notice that plus now takes a single argument (that is composed of two things). Super!

What's the point of this? Well, if you have a function that takes two arguments, and you have a pair of arguments, it is nice to know that you can apply the function to the arguments, and still get what you expect. And, in fact, the plumbing to do it already exists, so that you don't have to do things like explicit pattern matching. All you have to do is:

So what is partial function application? It is a different way to turn a function in two arguments into a function with one argument. It works differently though. Again, let's take (+) as an example. How might we turn it into a function that takes a single Int as an argument? We cheat!

That's the function that adds zero to any Int.

adds 1 to any Int. Etc. In each of these cases, (+) is "partially applied".

## @gsklee 2013-05-27 03:51:08

The difference between curry and partial application can be best illustrated through this following JavaScript example:

Partial application results in a function of smaller arity; in the example above,

`f`

has an arity of 3 while`partial`

only has an arity of 2. More importantly, a partially applied function wouldreturn the result right away upon being invoke, not another function down the currying chain. So if you are seeing something like`partial(2)(3)`

, it's not partial application in actuality.Further reading:

## @Maksim Gumerov 2017-02-08 13:10:11

" a partially applied function would return the result right away upon being invoke" - that's not correct, is it? when I partially apply a function, that expression returns a function, not "a result". Ok, you probably meant that this latter function, when called with the remaining arguments, returns the result, unlike digging one step down into currying. But no one actually says you have to specify all the remaining arguments: you can partially-apply the result of partial application, and that will once again be a function, not a "result"

## @Taoufik Dachraoui 2013-05-13 10:03:40

For me partial application must create a new function where the used arguments are completely integrated into the resulting function.

Most functional languages implement currying by returning a closure: do not evaluate under lambda when partially applied. So, for partial application to be interesting, we need to make a difference between currying and partial application and consider partial application as currying plus evaluation under lambda.

## @Ji Han 2012-10-11 19:40:41

I have answered this in another thread https://stackoverflow.com/a/12846865/1685865 . In short, partial function application is about fixing some arguments of a given multivariable function to yield another function with fewer arguments, while Currying is about turning a function of N arguments into a unary function which returns a unary function...[An example of Currying is shown at the end of this post.]

Currying is mostly of theoretical interest: one can express computations using only unary functions (i.e.

everyfunction is unary). In practice and as a byproduct, it is a technique which can make many useful (but not all) partial functional applications trivial, if the language has curried functions. Again, it is not the only means to implement partial applications. So you could encounter scenarios where partial application is done in other way, but people are mistaking it as Currying.(Example of Currying)In practice one would not just write

or the equivalent javascript

instead of

for the sake of Currying.

## @SpoonMeiser 2012-11-07 11:16:29

Would you say that currying is a specific case of partial application then?

## @Pacerier 2014-05-02 23:32:14

@SpoonMeiser, No, currying is not a specific case of partial application: A partial application of a 2-input function is not the same as currying the function. See stackoverflow.com/a/23438430/632951 .

## @dodgy_coder 2012-05-04 05:18:33

Note: this was taken from F# Basics an excellent introductory article for .NET developers getting into functional programming.