Discussion:
Intuitive explanation of currying.
(too old to reply)
n***@gmail.com
2012-07-15 13:17:19 UTC
Permalink
I was reading/reminded that 'lambda calculus is not easy'.
So I a got-out my copy of
http://en.wikipedia.org/wiki/Lambda_calculus
But I can't afford the effort to learn how to edit wikis.
So I'll put it here:- [my wiki contaminated by my 'comments']
Currying may best grasped intuitively through the use of an
example. Compare the function (x, y) | x*x + y*y with its curried
((x, y) | x*x + y*y)(5, 2) = 5*5 + 2*2 = 29. <-- f(5, 2) = 29
((x | (y | x*x + y*y))(5)) (2) <--- (functn) (arg)
(<1 arg> maps-to <lambda1Funct> (5) ) (2)
= (y | 5*5 + y*y) (2)
= 5*5 + 2*2 = 29 <----------------- * !!
and we see the uncurried and curried forms compute the same result.
So what? That's not an intuitive explanation.
Intuitive means related to concrete/familiar life.

Eg. take a 3D/volume: semi-sphere, rect-cube or a 'wedge' is
interesting; and place it on your x-y-coordinate 'pad'.

The task/function is to know the <heights above your x-y-pad>
of the top-surface. Like the heights of a mountain at a specific
longtitude, latitude.

For the wedge: if you know the x-value and the the y-value
is constant at THAT x-value, you've got the answer.

For the mountain: if you can only buy services of a flying-saucer
that gives the longtitude-to-terain-height-function for a FIXED
latitude, you've got the height, from you single parameter.

So the set of (x,y) tuples & f1 is collaped into an eqivalent:
[say] (x, y-cuts/slices/function) .
By induction, it extends to N-dimensions.

Here's a very intuitive example:
the fare for transport is quoted in a table, as being a function of
'route' and class. Where route means 'A to B' equals 'B to A'.
So 'Albany to Boston', class:2 costs $7,
and 'Boston to Albany', class:1 costs $9.

If you want to know the fare from 'Albany to Cooktown', class:3,
you don't need to provide both paramenters: 'route' and class.
You can just give the route, and ask for the singleton-function
[list of all prices for 'Albany to Cooktown' for all classes].

Thanks, I think I understand currying better now.
Do you?

== Chris Glur.

PS. explanations that I have of 'monads' are disasterous.
Василий Воронков
2012-07-16 14:12:25 UTC
Permalink
Your explanation doesn't really explain currying. It actually explains the whole concept of partial application. Currying is in fact a very simple concept.

Imagine, that we have language where a function can be applied only to one argument - there are no multiple argument functions at all. What we can do in such situation to imitate multiple argument functions? We can write functions that return other functions.

For example, a function for two arguments is a function for one argument that take this argument and returns another function for one argument. Here is an example in JavaScript:

function sum(x) {
return (function(y) { return x+y });
}

Applying:

sum(2)(2)

Or in a sane language:

sum = \x -> \y -> x+y

Applying:

sum 2 2 --That's equivalent to '(sum 2) 2' because of application left associativity

Of course, for this trick to work our language should support closures (because the nested function capture a argument of its parent functon). But if you understand closures it shouldn't be a problem for you.
I was reading/reminded that &#39;lambda calculus is not easy&#39;.
So I a got-out my copy of
http://en.wikipedia.org/wiki/Lambda_calculus
But I can&#39;t afford the effort to learn how to edit wikis.
So I&#39;ll put it here:- [my wiki contaminated by my &#39;comments&#39;]
&gt; Currying may best grasped intuitively through the use of an
&gt; example. Compare the function (x, y) | x*x + y*y with its curried
&gt; ((x, y) | x*x + y*y)(5, 2) = 5*5 + 2*2 = 29. &lt;-- f(5, 2) = 29
&gt; ((x | (y | x*x + y*y))(5)) (2) &lt;--- (functn) (arg)
&gt;
&gt; (&lt;1 arg&gt; maps-to &lt;lambda1Funct&gt; (5) ) (2)
&gt;
&gt; = (y | 5*5 + y*y) (2)
&gt; = 5*5 + 2*2 = 29 &lt;----------------- * !!
&gt; and we see the uncurried and curried forms compute the same result.
&gt;
So what? That&#39;s not an intuitive explanation.
Intuitive means related to concrete/familiar life.
Eg. take a 3D/volume: semi-sphere, rect-cube or a &#39;wedge&#39; is
interesting; and place it on your x-y-coordinate &#39;pad&#39;.
of the top-surface. Like the heights of a mountain at a specific
longtitude, latitude.
For the wedge: if you know the x-value and the the y-value
is constant at THAT x-value, you&#39;ve got the answer.
For the mountain: if you can only buy services of a flying-saucer
that gives the longtitude-to-terain-height-function for a FIXED
latitude, you&#39;ve got the height, from you single parameter.
[say] (x, y-cuts/slices/function) .
By induction, it extends to N-dimensions.
the fare for transport is quoted in a table, as being a function of
&#39;route&#39; and class. Where route means &#39;A to B&#39; equals &#39;B to A&#39;.
So &#39;Albany to Boston&#39;, class:2 costs $7,
and &#39;Boston to Albany&#39;, class:1 costs $9.
If you want to know the fare from &#39;Albany to Cooktown&#39;, class:3,
you don&#39;t need to provide both paramenters: &#39;route&#39; and class.
You can just give the route, and ask for the singleton-function
[list of all prices for &#39;Albany to Cooktown&#39; for all classes].
Thanks, I think I understand currying better now.
Do you?
== Chris Glur.
PS. explanations that I have of &#39;monads&#39; are disasterous.
I was reading/reminded that &#39;lambda calculus is not easy&#39;.
So I a got-out my copy of
http://en.wikipedia.org/wiki/Lambda_calculus
But I can&#39;t afford the effort to learn how to edit wikis.
So I&#39;ll put it here:- [my wiki contaminated by my &#39;comments&#39;]
&gt; Currying may best grasped intuitively through the use of an
&gt; example. Compare the function (x, y) | x*x + y*y with its curried
&gt; ((x, y) | x*x + y*y)(5, 2) = 5*5 + 2*2 = 29. &lt;-- f(5, 2) = 29
&gt; ((x | (y | x*x + y*y))(5)) (2) &lt;--- (functn) (arg)
&gt;
&gt; (&lt;1 arg&gt; maps-to &lt;lambda1Funct&gt; (5) ) (2)
&gt;
&gt; = (y | 5*5 + y*y) (2)
&gt; = 5*5 + 2*2 = 29 &lt;----------------- * !!
&gt; and we see the uncurried and curried forms compute the same result.
&gt;
So what? That&#39;s not an intuitive explanation.
Intuitive means related to concrete/familiar life.
Eg. take a 3D/volume: semi-sphere, rect-cube or a &#39;wedge&#39; is
interesting; and place it on your x-y-coordinate &#39;pad&#39;.
of the top-surface. Like the heights of a mountain at a specific
longtitude, latitude.
For the wedge: if you know the x-value and the the y-value
is constant at THAT x-value, you&#39;ve got the answer.
For the mountain: if you can only buy services of a flying-saucer
that gives the longtitude-to-terain-height-function for a FIXED
latitude, you&#39;ve got the height, from you single parameter.
[say] (x, y-cuts/slices/function) .
By induction, it extends to N-dimensions.
the fare for transport is quoted in a table, as being a function of
&#39;route&#39; and class. Where route means &#39;A to B&#39; equals &#39;B to A&#39;.
So &#39;Albany to Boston&#39;, class:2 costs $7,
and &#39;Boston to Albany&#39;, class:1 costs $9.
If you want to know the fare from &#39;Albany to Cooktown&#39;, class:3,
you don&#39;t need to provide both paramenters: &#39;route&#39; and class.
You can just give the route, and ask for the singleton-function
[list of all prices for &#39;Albany to Cooktown&#39; for all classes].
Thanks, I think I understand currying better now.
Do you?
== Chris Glur.
PS. explanations that I have of &#39;monads&#39; are disasterous.
Aatu Koskensilta
2012-07-16 14:40:04 UTC
Permalink
Post by Василий Воронков
Imagine, that we have language where a function can be applied only to
one argument - there are no multiple argument functions at all. What
we can do in such situation to imitate multiple argument functions? We
can write functions that return other functions.
Well, we can also write functions that take tuples as arguments. The
types A1 x A2 x ... x An --> C and A1 --> A2 --> ... --> An --> C are
(morally or literally, depending on the setting) isomorphic.
--
Aatu Koskensilta (***@uta.fi)

"Wovon man nicht sprechen kann, darüber muss man schweigen"
- Ludwig Wittgenstein, Tractatus Logico-Philosophicus
Василий Воронков
2012-07-16 14:46:21 UTC
Permalink
Yes, but in order to do that, we have to introduce another concept - a tuple. The solution with currying is the most "minimalistic" approach to simulation of multiple argument functions, which also allows us to partially apply functions.
&gt; Imagine, that we have language where a function can be applied only to
&gt; one argument - there are no multiple argument functions at all. What
&gt; we can do in such situation to imitate multiple argument functions? We
&gt; can write functions that return other functions.
Well, we can also write functions that take tuples as arguments. The
(morally or literally, depending on the setting) isomorphic.
--
&quot;Wovon man nicht sprechen kann, darüber muss man schweigen&quot;
- Ludwig Wittgenstein, Tractatus Logico-Philosophicus
n***@gmail.com
2012-07-20 08:26:55 UTC
Permalink
Post by Василий Воронков
Your explanation doesn't really explain currying. It actually explains the
whole concept of partial application. Currying is in fact a very simple
concept.
Imagine, that we have language where a function can be applied only to one
argument - there are no multiple argument functions at all. What we can do
in such situation to imitate multiple argument functions? We can write
functions that return other functions.
For example, a function for two arguments is a function for one argument
that take this argument and returns another function for one argument.
function sum(x) {
return (function(y) { return x+y });
}
sum(2)(2)
sum =3D \x -> \y -> x+y
sum 2 2 --That's equivalent to '(sum 2) 2' because of application left associativity
Of course, for this trick to work our language should support closures
(because the nested function capture a argument of its parent functon).
But if you understand closures it shouldn't be a problem for you.
We are talking past each other.
My attempt to enlarge on the TITLE of my post, has failed.
There are several levels here.
One is what 'currying' IS: which I don't clain to know and
I just 'pasted' from the wikipedia.
Second is the INTUITIVE explanation / translation of what
I read in the wiki. Admittedly <intuitive> must be subjective;
but I believe that most writers don't even try to think what is
intuitive.

Lacking training in this field: psychology/cog-sci, I DO still
maintain that "II + II = IIII" is more intuitive than "2+2=4".
Don't you think the east-asians math superiority comes
from their use of 'pictogram writing', instead sound-based?

For me the important point of your post is [one of ] the
REASON for [what I'll call currying]: is if you've got an
automata which accepts only one arg and returns a singleton;
like *nix-piping, or forth.

IMO explanations from writers who resort to 'their'
language/s are the most unintuitive. Your examples added no
value for me.

== Chris Glur.
Aatu Koskensilta
2012-07-20 13:04:47 UTC
Permalink
Don't you think the east-asians math superiority comes from their use
of 'pictogram writing', instead sound-based?
No.
--
Aatu Koskensilta (***@uta.fi)

"Wovon man nicht sprechen kann, darüber muss man schweigen"
- Ludwig Wittgenstein, Tractatus Logico-Philosophicus
Barb Knox
2012-07-21 05:46:35 UTC
Permalink
Don't you think the east-asians math superiority comes from their use
of 'pictogram writing', instead sound-based?
No.
But it plausibly does account for some of their apparent superiority in
rote memorisation. Does anyone her know of any published experimental
work regarding this?
--
---------------------------
| BBB b \ Barbara at LivingHistory stop co stop uk
| B B aa rrr b |
| BBB a a r bbb | Quidquid latine dictum sit,
| B B a a r b b | altum videtur.
| BBB aa a r bbb |
-----------------------------
Dirk Thierbach
2012-07-21 06:32:53 UTC
Permalink
Post by Barb Knox
Don't you think the east-asians math superiority comes from their use
of 'pictogram writing', instead sound-based?
BTW, when I was a teaching assistant at university, I taught some
first year asian students in mathematics. Maube it was because they
had enough other problems at that time to deal with (another language,
culture shock, different level of education after finishing school),
but they were in no way superior in the abilities that really count
in maths, namely abstract thinking, careful reasoning and detecting
patterns.
Post by Barb Knox
No.
But it plausibly does account for some of their apparent superiority in
rote memorisation.
Though I would blame this first on an education system where a large
part of learning, no matter what subject, is just rote memorisation. If
you train something often enough, you become good at it.

Of course learning 2000 Kanji/Hanzi counts as part of the training. :-)
Post by Barb Knox
Does anyone her know of any published experimental work regarding this?
That would be difficult to do if you want to rule out factors like the
one above.

- Dirk
n***@gmail.com
2012-07-21 18:42:45 UTC
Permalink
Co-ordinating *my* thead is like trying to herd cats ?
Post by Barb Knox
Don't you think the east-asians math superiority comes from their use
of 'pictogram writing', instead sound-based?
No.
Let me try to fill-in-the-dots:
anybody who's learned how to read schematic-diagrams or music,
knows the MASSIVE advantage of going directly from the <image> to
the <concept>, instead of going via the extra stage of the <sound
repesenting the word/s> to the concept.
Post by Barb Knox
But it plausibly does account for some of their apparent superiority in
rote memorisation.
No, I suspect that's just cultural:
authoritarian society stiffles creativety;
so simplistic method of learning i.e. rote memorisation is used.
I.e. brute-force-and-ignorance.

So, I was suggesting that since any 2-arg-function can be represented
by [is isomorphic to] a 3-dimensional-space, an intuitive way to
explain currying/partial-implemenataion is by getting a 2-dimensional
slice-out-of-the-3-dimensional-space.

And then I was fishing for a similarly intuitive explanation of
monads. But I got none -- yet.

But geometrical-thinking may NOT be intuitive to others, even if
the APL high-priest who's award winning ACM paper was entitled
<notation as an aid the thought> and he was VERY graphic.

== Chris Glur.

PS. <Babs> asked about literature on this.
'The stuff of thought' by Steven Pinker [from the library] was
brilliant. And a 4-part of <google:BBC+Reith+lecture> in the
last decade title < ? the mind ?> authored by a <Tamil-name>,
like 'Malaburi..' is a good easy read.
Steve Schafer
2012-07-21 19:21:15 UTC
Permalink
Post by n***@gmail.com
anybody who's learned how to read schematic-diagrams or music,
knows the MASSIVE advantage of going directly from the <image> to
the <concept>, instead of going via the extra stage of the <sound
repesenting the word/s> to the concept.
I can read schematic diagrams and music, as well as various other
graphical notations (Feynman diagrams, etc.). While I will agree that
those specialized notations do have substantial advantages in their
respective fields, that advantage arises primarily out of the brevity of
the notation rather than intuition. Thus, the disadvantage of those
notations is that you have to learn their rules before you can use them
effectively. There is little that is truly "intuitive" about the
notations; it's almost all learned.

An example: I was recently given a piece of clothing that was
manufactured in Italy. The care label sewn into the piece has no written
words; it is just a series of pictographic symbols that represent the
various things that you can and cannot do as far as caring for the piece
(e.g., machine wash, use medium iron, do not dry clean, etc.). Although
I am familiar with the concept of this "language," I don't know all of
the "words." So I had to go online to figure out what they meant. The
ironing symbol is partially intuitive in that it looks like an
old-fashioned clothes iron, but it has additional subsymbols (one ore
more dots inside) that alter the meaning in a way that is hardly
intuitive at all (more dots means hotter iron, but unless you know what
the scale is, it doesn't really help much). And the symbol for "do not
dry clean" (an X superimposed on a circle) is not intuitive at all. (The
"X" is well established as meaning "do not...," but even that is a
learned, not intuitive, interpretation. I have no idea why a circle
means "dry clean.")

So getting back to the written word... Written language is, essentially,
a general-purpose and extensible pictographic notation. For the most
part, the pictures have completely lost their original meanings, but
they're still pictures, just a different kind. I can't speak for others,
but when I'm reading text, there is no "extra stage of the <sound
repesenting the word/s>"; for familiar words, the _visual_ arrangement
of symbols in a word is, as far as I can tell, translated directly into
the concept in my brain.

-Steve Schafer
Mok-Kong Shen
2012-07-21 20:56:24 UTC
Permalink
Am 21.07.2012 21:21, schrieb Steve Schafer:
[snip]
Post by Steve Schafer
So getting back to the written word... Written language is, essentially,
a general-purpose and extensible pictographic notation. For the most
part, the pictures have completely lost their original meanings, but
they're still pictures, just a different kind. I can't speak for others,
but when I'm reading text, there is no "extra stage of the <sound
repesenting the word/s>"; for familiar words, the _visual_ arrangement
of symbols in a word is, as far as I can tell, translated directly into
the concept in my brain.
I find it very interesting that you wrote this (about European
languages, I presume), for I thought till the present that that
applies only to a language like Chinese where the characters have
genuine pictographic origins.

M. K. Shen
Steve Schafer
2012-07-21 22:17:04 UTC
Permalink
On Sat, 21 Jul 2012 22:56:24 +0200, Mok-Kong Shen
Post by Mok-Kong Shen
I find it very interesting that you wrote this (about European
languages, I presume), for I thought till the present that that
applies only to a language like Chinese where the characters have
genuine pictographic origins.
M. K. Shen
The modern Latin alphabet can be traced back to Phoenecian, but from
that point on the trail runs cold. There is, however, evidence that many
of the letters can be traced directly to pictographic representations.
For example, the letter "A" is linked to the word for "ox," and it's
pretty clear from the Phoenecian rendering of that glyph that it started
out as a literal picture of an ox's head, complete with horns.

There was something that circulated around the Internet a few years
back:

--------8<--------

I cnduo't bvleiee taht I culod aulaclty uesdtannrd waht I was rdnaieg.
Unisg the icndeblire pweor of the hmuan mnid, aocdcrnig to rseecrah at
Cmabrigde Uinervtisy, it dseno't mttaer in waht oderr the lterets in a
wrod are, the olny irpoamtnt tihng is taht the frsit and lsat ltteer be
in the rhgit pclae. The rset can be a taotl mses and you can sitll raed
it whoutit a pboerlm. Tihs is bucseae the huamn mnid deos not raed ervey
ltteer by istlef, but the wrod as a wlohe. Aaznmig, huh? Yaeh and I
awlyas tghhuot slelinpg was ipmorantt! See if yuor fdreins can raed tihs
too.

-------->8--------

As it turns out, this was a bit of a hoax, in that the jumbled words
were in fact carefully crafted to remain legible. But the fact that an
English reader can read it at all tells us that there is something
complicated going on in our visual systems when we read. Here's a good
overview of what we know about word recognition (in European scripts, at
least):

http://www.microsoft.com/typography/ctfonts/WordRecognition.aspx

TL;DR version: It appears that our visual system processes and
recognizes groups of 5-10 letters in parallel. With shorter words, the
groups are large enough to encompass one or more entire words; in longer
words, we process them in chunks.

-Steve Schafer
Shmuel (Seymour J.) Metz
2012-07-23 03:14:07 UTC
Permalink
Post by Steve Schafer
The modern Latin alphabet can be traced back to Phoenecian,
As can the Cyrillic and Greek alphabets, and various Semitic alphabets
by way of Aramaic.
--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to ***@library.lspace.org
Shmuel (Seymour J.) Metz
2012-07-23 02:56:28 UTC
Permalink
Post by Steve Schafer
An example: I was recently given a piece of clothing that was
manufactured in Italy. The care label sewn into the piece has no
written words; it is just a series of pictographic symbols that
represent the various things that you can and cannot do as far as
caring for the piece (e.g., machine wash, use medium iron, do not dry
clean, etc.).
I refer to those as icons that are equally unintelligible in any
language.
--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to ***@library.lspace.org
Aatu Koskensilta
2012-07-24 14:13:00 UTC
Permalink
Post by n***@gmail.com
anybody who's learned how to read schematic-diagrams or music,
knows the MASSIVE advantage of going directly from the <image> to
the <concept>, instead of going via the extra stage of the <sound
repesenting the word/s> to the concept.
This is an argument for specialized notation in mathematics. It has
nothing to do with, say, the Chinese writing system. There's nothing
remotely like "going directly from the image to the concept" involved in
reading Chinese (or other similar scripts). You seem to be under the
mistaken idea that Chinese characters are pictograms. They're not --
indeed can not be; it's not Pictionary. A dog looks like something,
perhaps. But what does being slow look like, or a measurable cardinal,
communism, pining for the happy days of old, primitive recursion, being
directed at something, taking place in the future, being owned by
someone, not taking place?
Post by n***@gmail.com
No, I suspect that's just cultural: authoritarian society stiffles
creativety; so simplistic method of learning i.e. rote memorisation is
used. I.e. brute-force-and-ignorance.
Alas, this is simply not so. See

http://pinyin.info/readings/texts/moser.html/

for an informed rant about the horrors of the Chinese writing
system. There's nothing "intuitive" about it and rote memorization
simply can't be avoided when learning the system.
Post by n***@gmail.com
And then I was fishing for a similarly intuitive explanation of
monads. But I got none -- yet.
Monads are a mathematical abstraction. As with any such abstraction,
the most important thing to keep in mind is that whenever one gets
stuck, it's time to go back to the definition. Understanding and
intuition comes with practice, playing with examples, and so on. It's
unrealistic to expect any analogy or metaphor alone to be enough,
although they may of course be illuminating and helpful. It's also
unrealistic to expect any one "intuitive explanation" to be helpful to
everyone. What is intuitive depends on what one is familiar with. Case
in point, when reading physics texts I often have to apply the metaphors
and explanations backwards. They will explain that this or that bit of
mathematics is just like this bit of physics, if you squint your eyes
just so, hoping this will allow physics students to grasp the necessary
mathematical insight, idea, technique, concept. Since I know virtually
no physics, but do know a bit of mathematics, I will instead develop
some (vague and indefinite) intuition or understanding of the physics
involved, by relating it to mathematical arcana I feel at home with.
--
Aatu Koskensilta (***@uta.fi)

"Wovon man nicht sprechen kann, darüber muss man schweigen"
- Ludwig Wittgenstein, Tractatus Logico-Philosophicus
Loading...