What is the advantage of currying?
Posted
by
Mad Scientist
on Programmers
See other posts from Programmers
or by Mad Scientist
Published on 2013-02-01T19:36:02Z
Indexed on
2013/11/09
10:15 UTC
Read the original article
Hit count: 457
functional-programming
|currying
I just learned about currying, and while I think I understand the concept, I'm not seeing any big advantage in using it.
As a trivial example I use a function that adds two values (written in ML). The version without currying would be
fun add(x, y) = x + y
and would be called as
add(3, 5)
while the curried version is
fun add x y = x + y
(* short for val add = fn x => fn y=> x + y *)
and would be called as
add 3 5
It seems to me to be just syntactic sugar that removes one set of parentheses from defining and calling the function. I've seen currying listed as one of the important features of a functional languages, and I'm a bit underwhelmed by it at the moment. The concept of creating a chain of functions that consume each a single parameter, instead of a function that takes a tuple seems rather complicated to use for a simple change of syntax.
Is the slightly simpler syntax the only motivation for currying, or am I missing some other advantages that are not obvious in my very simple example? Is currying just syntactic sugar?
© Programmers or respective owner