Yuce's Blog

Cognitive dissonance is yoga for the brain.*

Currying in Marvin

2005-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 com­pu­ta­tion (data attached continue.

marvin, currying

Another Currying Example in Marvin

2005-04-12

Please see my previous post before if you haven't done so.

I've quoted David Mertz's article Charming Python in my previous post. In that article, (besides other things) a Haskell function is curryied as:

computation a b c d = (a + b^2+ c^3 + d^4)

Then it is filled as follows:

fillOne   = computation 1
fillTwo   = fillOne 2
fillThree = fillTwo 3
answer    = fillThree 5

and the answer is 657. The same thing can be done in Marvin:

[ swap 2 ** + swap 3 ** + swap 4 ** + ] :computation
[ 1 \computation ] :fillOne
[ 2 \fillOne ] 

marvin, currying