Diigo Diary Bookmarks 03/02/2007
Currying - Wikipedia, the free encyclopedia Annotated
In mathematics, computer science and linguistics (semantics), currying or Schönfinkelisation[1] is the technique of transforming a function that takes multiple arguments into a function that takes a single argument (the other arguments having been specified by the curry).
ML
Suppose that plus is a function taking two arguments x and y and returning x + y. In the ML programming language we would define it as follows:
plus = fn(x, y) => x + y
and plus(1, 2) returns 3 as we expect.
The curried version of plus takes a single argument x and returns a new function which takes a single argument y and returns x + y. In ML we would define it as follows:
curried_plus = fn(x) => fn(y) => x + y
and now when we call curried_plus(1) we get a new function that adds 1 to its argument:
plus_one = curried_plus(1)
and now plus_one(2) returns 3 and plus_one(7) returns 8.