[ ^ CSE 341 | section index | <-- previous ]

Currying

Currying is basically a way of forcing all functions in the universe to have exactly one argument. This results in greater language regularity, which makes things like automated analysis simpler. Languages that do currying have "fewer concepts" to deal with than languages that have multiple argument functions.

add:: => num->num->num add 5:: => num->num

"Manual currying" is possible in Scheme:

(define (add x y) (+ x y)) ; uncurried (define (curried-add x) ; curried form (lambda (y) (+ x y))) ((curried-add x) y) ; curried application

Polymorphic functions

Consider the following function reverse:

reverse [] = [] reverse (a:x) = (reverse x) ++ [a] reverse:: => [*]->[*]

The function can take elements of any type; therefore, its type is polymorphic. Polymorphic functions are implicitly available in Scheme; Miranda provides static type support. Incidentally, static polymorphic functions are available, with a lot more heavy syntactic handwaving, in C++:

template<class T> T sum( T* array, int numelements ) { T retval; for (int i=0; i<numelements; i++) { retval = retval + array[i]; } return retval; }

Last modified: Mon Apr 3 21:17:56 PDT 2000