Encyclopedia > Curried function

  Article Content

Currying

Redirected from Curried function

Currying is a functional programming language operation performed on functions of more than one argument, named after the logician Haskell Curry. Currying a function f of two arguments produces a function g of one argument that returns a function of one argument such that f(x, y) equals (g(x))(y), or in Lisp notation (f x y) equals ((g x) y). By extension, fully currying a function f of three arguments produces g such that f(x, y, z) equals ((g(x))(y))(z), or in Lisp notation (f x y z) equals (((g x) y) z).

To do currying in the Scheme programming language:

 (define curry2
   (lambda (f)
     (lambda (x)    ; take the first argument
       (lambda y    ; and the rest of the args as a list
         (f x . y)))))

If g equals (curry2 f), then (f x y) equals ((g x) y), and (f x y z) equals ((g x) y z).

These languages automatically fully curry functions called with too few arguments:

See also:



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
East Islip, New York

... of the census of 2000, there are 14,078 people, 4,578 households, and 3,731 families residing in the town. The population density is 1,322.5/km² (3,428.5/mi²). ...

 
 
 
This page was created in 23.9 ms