The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Message from discussion Intuitive explanation of currying.

```Received: by 10.224.176.67 with SMTP id bd3mr8009213qab.8.1343000120285;
Sun, 22 Jul 2012 16:35:20 -0700 (PDT)
Received: by 10.66.89.199 with SMTP id bq7mr1367358pab.32.1343000023122;
Sun, 22 Jul 2012 16:33:43 -0700 (PDT)
From: =?KOI8-R?B?98HTyczJyiD3z9LPzsvP1w==?= <ba...@voronkov.name>
Newsgroups: comp.lang.functional
Subject: Re: Intuitive explanation of currying.
Date: Mon, 16 Jul 2012 07:12:25 -0700 (PDT)
Lines: 163
References: <jtufst\$fgq\$1@dont-email.me>
NNTP-Posting-Host: 95.143.213.226
Mime-Version: 1.0
X-Trace: posting.google.com 1342447945 24821 127.0.0.1 (16 Jul 2012 14:12:25 GMT)
NNTP-Posting-Date: Mon, 16 Jul 2012 14:12:25 +0000 (UTC)
posting-account=sxKr-woAAAA4yGx_aYaT9sXsGM0LWgSB
User-Agent: G2/1.0
Bytes: 7762
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Your explanation doesn't really explain currying. It actually explains the =
whole concept of partial application. Currying is in fact a very simple con=
cept.

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 func=
tions that return other functions.

For example, a function for two arguments is a function for one argument th=
at take this argument and returns another function for one argument. Here i=
s an example in JavaScript:

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

Applying:

sum(2)(2)

Or in a sane language:

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

Applying:

sum 2 2 --That's equivalent to '(sum 2) 2' because of application left asso=
ciativity

Of course, for this trick to work our language should support closures (bec=
ause the nested function capture a argument of its parent functon). But if =
you understand closures it shouldn't be a problem for you.

On Sunday, July 15, 2012 5:17:19 PM UTC+4, (unknown) wrote:
> 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;]
>=20
> &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;  form, x | (y | x*x + y*y). Given two arguments, we have:
> &gt;  ((x, y) | x*x + y*y)(5, 2) =3D 5*5 + 2*2 =3D 29.     &lt;-- f(5, 2)=
=3D 29
> &gt;    However, using currying, we have:
> &gt;    ((x | (y | x*x + y*y))(5))   (2)   &lt;--- (functn) (arg)
> &gt;   =20
> &gt; (&lt;1 arg&gt; maps-to &lt;lambda1Funct&gt; (5) )  (2)
> &gt;=20
> &gt;    =3D (y | 5*5 + y*y) (2)
> &gt;    =3D 5*5 + 2*2 =3D 29   &lt;----------------- * !!
> &gt;    and we see the uncurried and curried forms compute the same resul=
t.
> &gt;=20
> So what? That&#39;s not an intuitive explanation.
> Intuitive means related to concrete/familiar life.
>=20
> Eg. take a 3D/volume: semi-sphere, rect-cube or a &#39;wedge&#39; is=20
>=20
> of the top-surface. Like the heights of a mountain at a specific
> longtitude, latitude.
>=20
> 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.
>=20
> 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.
>=20
> So the set of (x,y) tuples &amp; f1 is collaped into an eqivalent:
> [say] (x, y-cuts/slices/function) .  =20
> By induction, it extends to N-dimensions.
>=20
> Here&#39;s a very intuitive example:
> 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.
>=20
> 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=20
> [list of all prices for &#39;Albany to Cooktown&#39; for all classes].
>=20
> Thanks, I think I understand currying better now.
> Do you?
>=20
> =3D=3D Chris Glur.
>=20
> PS. explanations that I have of &#39;monads&#39; are disasterous.

On Sunday, July 15, 2012 5:17:19 PM UTC+4, (unknown) wrote:
> 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;]
>=20
> &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;  form, x | (y | x*x + y*y). Given two arguments, we have:
> &gt;  ((x, y) | x*x + y*y)(5, 2) =3D 5*5 + 2*2 =3D 29.     &lt;-- f(5, 2)=
=3D 29
> &gt;    However, using currying, we have:
> &gt;    ((x | (y | x*x + y*y))(5))   (2)   &lt;--- (functn) (arg)
> &gt;   =20
> &gt; (&lt;1 arg&gt; maps-to &lt;lambda1Funct&gt; (5) )  (2)
> &gt;=20
> &gt;    =3D (y | 5*5 + y*y) (2)
> &gt;    =3D 5*5 + 2*2 =3D 29   &lt;----------------- * !!
> &gt;    and we see the uncurried and curried forms compute the same resul=
t.
> &gt;=20
> So what? That&#39;s not an intuitive explanation.
> Intuitive means related to concrete/familiar life.
>=20
> Eg. take a 3D/volume: semi-sphere, rect-cube or a &#39;wedge&#39; is=20
>=20
> of the top-surface. Like the heights of a mountain at a specific
> longtitude, latitude.
>=20
> 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.
>=20
> 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.
>=20
> So the set of (x,y) tuples &amp; f1 is collaped into an eqivalent:
> [say] (x, y-cuts/slices/function) .  =20
> By induction, it extends to N-dimensions.
>=20
> Here&#39;s a very intuitive example:
> 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.
>=20
> 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=20
> [list of all prices for &#39;Albany to Cooktown&#39; for all classes].
>=20
> Thanks, I think I understand currying better now.
> Do you?
>=20
> =3D=3D Chris Glur.
>=20
> PS. explanations that I have of &#39;monads&#39; are disasterous.

```