Home

currying

Currying is a transformation in functional programming that converts a function that takes multiple arguments into a sequence of functions, each taking a single argument. In other words, a function f(a, b, c) can be viewed as f(a)(b)(c). The overall result remains the same, but intermediate results are themselves functions waiting for the next argument.

The term currying is named after Haskell Curry, a logician whose name became associated with the technique.

How it works in practice varies by language. In a curried view, a two-argument function is seen

Relation to partial application is close but distinct. Partial application fixes some arguments of a function

The
idea
has
roots
in
mathematical
logic
and
lambda
calculus,
with
earlier
work
by
other
thinkers,
but
currying
as
a
programming
concept
is
most
commonly
discussed
in
relation
to
functional
languages
and
their
handling
of
function
application.
as
a
function
that
takes
the
first
argument
and
returns
a
new
function
that
takes
the
second.
For
example,
a
function
add(x)
that
returns
a
function
y
->
x
+
y
can
be
applied
as
add(2)(3)
to
produce
5.
In
a
language
like
Haskell,
functions
are
curried
by
default:
a
function
of
two
arguments
has
a
type
a
->
b
->
c
and
can
be
partially
applied.
In
other
languages,
currying
may
be
achieved
explicitly
via
closures
or
library
helpers,
or
it
may
not
be
built
in
at
all.
to
produce
a
new
function
with
fewer
arguments;
in
languages
with
automatic
currying,
partial
applications
often
align
with
currying
semantics.
Currying
supports
function
composition
and
modular
reuse
by
enabling
higher-order
construction
of
specialized
functions
from
more
general
ones.