Currying in Marvin2005-04-12
Yesterday, I figured out a way (which was very obvious) to curry a routine in Marvin. First of all, what's currying?
Currying is named after the logician Haskell Curry. (...) The underlying insight of "currying" is that it is possible to treat (almost) every function as a partial function of just one argument. All that is necessary for currying to work is to allow the return value of functions to themselves be functions, but with the returned functions narrowed or closer to completion. (...) each successive call to a curried return function fills in more of the data involved in a final computation (data attached to a procedure).
(define (times y) (lambda (x) (* y x)))
We can then use this to define a function that doubles its argument.
(define (double x) ((times 2) x))
Then we can use "double" just like any other function:
Simple, isn't it? But currying is a real headache for non-functional languages; even for Python in some extent. Below is how to do it Marvin:
[ * ] :times [ 2 \times ] :double
To call double, just write:
How elegant and natural, isn't it?