[plt-scheme] Why do layman programmers care about Currying?

From: Richard Cleis (rcleis at mac.com)
Date: Sat Jan 3 00:29:32 EST 2009

On Jan 2, 2009, at 7:57 AM, Grant Rettke wrote:

> On Tue, Dec 30, 2008 at 11:44 PM, Richard Cleis <rcleis at me.com> wrote:
>> On Dec 30, 2008, at 9:12 PM, Grant Rettke wrote:
>>> Why do layman (working programmers) care about Currying? Or how are
>>> they applied in daily use to help one out?
>> I'm not sure if you are referring to 'using a function that curries  
>> other
>> functions,' or if you mean (as the wikisnip says) "if you fix some
>> arguments, you get a function of the remaining arguments." I  
>> manually do the
>> latter frequently, and it's one of the reasons I like Scheme so much.
> I don't understand the practical application of currying in Scheme, so
> I'm not asking about one or the other; the wikipedia link was just my
> going in position on trying to understand what is currying.
> When you do apply the latter, what are the idioms or patterns that you
> most often encounter?

I often encounter core functions of at least several arguments, most  
or all of which are results of independent computations of diverse  
complexity.  Efficiency is enhanced by ordering the arguments by  
complexity and using Curry-related closures.  The organization of the  
program tends to be more appealing to me since variables contain  
intermediate functions of specific meaning, rather than specific data  
that are used by a generally-named core function. In other words,  
Currying permits repeated use of intermediate functions as an  
alternative to overtly managing arguments to a core function.

> I understand the idea of using bindings to capture state, but I don't
> see how that translates into normal usage. For example, if you write
> (define (((foo a) b) c)
>  (λ () (do-something-to a b c)))
> you will get a function back 3 times, but only the third time is the
> result you expect. How do you know when to stop, keep track of how
> many times you called it? Is this a good example?

The earlier post,


is a specific example of producing intermediate functions using  
keywords. Below is a way to use the Currying form that you present.   
The function that would return 'earth' is used much less often than  
the core function.  The function that would return 'telescope' is used  
more often, but not as much as the core function.  The outer function  
would then be used perhaps thousands or millions of times to generate  
flightpaths of one or more ufos.

(define  (((view-info earth) telescope) ufo)
   (string-append "Geometric calcs of: " ufo ", " telescope ", " earth))

(((view-info "earth at 12:00") "big telescope") "green ufo at 12:01")
; a test, but not practical

(define  use-earth-at-12:00 (view-info "earth at 12:00"))

(define  view-from-starfire (use-earth-at-12:00 "starfire telescope"))
(define  view-from-firepond (use-earth-at-12:00 "firepond telescope"))

(define  ufos (list "green-ufo-at-12:01" "green-ufo-at-12:02" "red-ufo- 

(map view-from-starfire ufos)
(map view-from-firepond ufos)

Welcome to DrScheme, version 4.1 [3m].
Language: Module; memory limit: 128 megabytes.
"Geometric calcs of: green ufo at 12:01, big telescope, earth at 12:00"
("Geometric calcs of: green-ufo-at-12:01, starfire telescope, earth at  
  "Geometric calcs of: green-ufo-at-12:02, starfire telescope, earth  
at 12:00"
  "Geometric calcs of: red-ufo-at-12:01, starfire telescope, earth at  
("Geometric calcs of: green-ufo-at-12:01, firepond telescope, earth at  
  "Geometric calcs of: green-ufo-at-12:02, firepond telescope, earth  
at 12:00"
  "Geometric calcs of: red-ufo-at-12:01, firepond telescope, earth at  


"We ascribe beauty to that which is simple."
--Ralph Waldo Emerson

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090102/3788d3bf/attachment.html>

Posted on the users mailing list.