<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Self-currying JavaScript functions</title>
	<atom:link href="http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/</link>
	<description>This dirt was a building before</description>
	<pubDate>Wed, 19 Nov 2008 16:49:53 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: Chris Done</title>
		<link>http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-3037</link>
		<dc:creator>Chris Done</dc:creator>
		<pubDate>Sun, 16 Mar 2008 14:22:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-3037</guid>
		<description>Hi. Maybe it is helpful to consider that it is based on λ-calculus, and in λ-calculus, functions can only take one argument. Therefore, all functions in Haskell take one argument. So for functions with more than one argument, currying is necessary.</description>
		<content:encoded><![CDATA[<p>Hi. Maybe it is helpful to consider that it is based on λ-calculus, and in λ-calculus, functions can only take one argument. Therefore, all functions in Haskell take one argument. So for functions with more than one argument, currying is necessary.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ExcuseMe</title>
		<link>http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2803</link>
		<dc:creator>ExcuseMe</dc:creator>
		<pubDate>Fri, 08 Feb 2008 17:13:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2803</guid>
		<description>but why should I care about this stuff?! Except for constructing weird syntax function calls or whatever. How does it help me?</description>
		<content:encoded><![CDATA[<p>but why should I care about this stuff?! Except for constructing weird syntax function calls or whatever. How does it help me?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Morten Barklund</title>
		<link>http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2794</link>
		<dc:creator>Morten Barklund</dc:creator>
		<pubDate>Thu, 07 Feb 2008 15:22:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2794</guid>
		<description>"multifunction" =&#62; "multi argument function" of course.

And another funny thing is, that the returned function of course also collect arguments when invoked without any at all:

&lt;pre&gt;&lt;code&gt;add()()()()(1)()()()(2,3);&lt;/code&gt;&lt;/pre&gt;

Very silly, but conceptually sound.</description>
		<content:encoded><![CDATA[<p>&#8220;multifunction&#8221; =&gt; &#8220;multi argument function&#8221; of course.</p>
<p>And another funny thing is, that the returned function of course also collect arguments when invoked without any at all:</p>
<pre><code>add()()()()(1)()()()(2,3);</code></pre>
<p>Very silly, but conceptually sound.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Morten Barklund</title>
		<link>http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2793</link>
		<dc:creator>Morten Barklund</dc:creator>
		<pubDate>Thu, 07 Feb 2008 15:18:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2793</guid>
		<description>Actually this concept does more than curry. If curry is transforming a multifunction into a series of single argument function, then this is achieved by the above - among other things. Because as another commenter asks: "how to implement uncurry?".

But the function returned is all spices! It works with any of 1-n arguments and will just collect and remember how many has been given and return a (n-"given arguments")-ary function that still can accept less than this value. The resulting function is thus both curried and uncurried.

If you want to create uncurry, which returns a function, that only can accept all arguments (or will invoke the function with only the given arguments), then you simply need to store the function reference on the function instance (as in my implementation) and return this from the given function:

&lt;pre&gt;&lt;code&gt;function curry(f, n) {
  var g = function() {
    var c = arguments.callee;
    if (c._len &#60;= arguments.length)
      return c._func.apply(null, arguments);
    return bind(c, arguments);
  }
  g._len = n &#124;&#124; f.length;
  g._func = f;
  return g;
}
function uncurry(f) {
  return f._func &#124;&#124; f;
}
var a = function(a,b) {return a+b;}
assert(a == uncurry(curry(a)));&lt;/code&gt;&lt;/pre&gt;


It might not be interesting at all, but it works.

Regarding the discussion of the definition of curry, I was reading more along the lines of the Wikipedia-definition, but I see your point. The Prototype function curry is called partial in MochiKit anyway. We might need a new term for this kind of function, as it somehow defies current definitions. Brave new world ;)</description>
		<content:encoded><![CDATA[<p>Actually this concept does more than curry. If curry is transforming a multifunction into a series of single argument function, then this is achieved by the above - among other things. Because as another commenter asks: &#8220;how to implement uncurry?&#8221;.</p>
<p>But the function returned is all spices! It works with any of 1-n arguments and will just collect and remember how many has been given and return a (n-&#8221;given arguments&#8221;)-ary function that still can accept less than this value. The resulting function is thus both curried and uncurried.</p>
<p>If you want to create uncurry, which returns a function, that only can accept all arguments (or will invoke the function with only the given arguments), then you simply need to store the function reference on the function instance (as in my implementation) and return this from the given function:</p>
<pre><code>function curry(f, n) {
  var g = function() {
    var c = arguments.callee;
    if (c._len &lt;= arguments.length)
      return c._func.apply(null, arguments);
    return bind(c, arguments);
  }
  g._len = n || f.length;
  g._func = f;
  return g;
}
function uncurry(f) {
  return f._func || f;
}
var a = function(a,b) {return a+b;}
assert(a == uncurry(curry(a)));</code></pre>
<p>It might not be interesting at all, but it works.</p>
<p>Regarding the discussion of the definition of curry, I was reading more along the lines of the Wikipedia-definition, but I see your point. The Prototype function curry is called partial in MochiKit anyway. We might need a new term for this kind of function, as it somehow defies current definitions. Brave new world <img src='http://blog.jcoglan.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2791</link>
		<dc:creator>James</dc:creator>
		<pubDate>Wed, 06 Feb 2008 23:33:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2791</guid>
		<description>Just to clear up a couple of things: first, as defined in the Haskell language:

"Currying is the process of transforming a function that takes multiple arguments into a function that takes just a single argument and returns another function if any arguments are still needed." - &lt;a href="http://www.haskell.org/haskellwiki/Currying" rel="nofollow"&gt;Haskell docs&lt;/a&gt;

This is what &lt;tt&gt;toSelfCurrying()&lt;/tt&gt; does. However, according to Wikipedia:

"In computer science, currying, invented by Moses Schönfinkel and Gottlob Frege, is the technique of transforming a function that takes multiple arguments into a function that takes a single argument (the other arguments having been specified by the curry)." - &lt;a href="http://en.wikipedia.org/wiki/Currying" rel="nofollow"&gt;Wikipedia&lt;/a&gt;

So there's room for debate. It looks to me (naive as I am) as though Haskell is a special case because all Haskell functions are single-argument functions, so you need to use currying to build multi-argument functions. The discrepancy seems to be over whether pre-set arguments are set with the currying operation. &lt;tt&gt;toSelfCurrying()&lt;/tt&gt; is essentially equivalent to currying in Haskell, while Prototype's &lt;tt&gt;curry()&lt;/tt&gt; is more in tune with the Wikipedia definition, taking into account JavaScript's flexibility. Given that the word 'currying' is a reference to Haskell B. Curry, I'm inclined to side with the Haskell definition of currying, while referring to Prototype's &lt;tt&gt;curry()&lt;/tt&gt; as partial application. Apart from anything, &lt;tt&gt;partial()&lt;/tt&gt; and &lt;tt&gt;curry()&lt;/tt&gt; just seem like better nomenclature than &lt;tt&gt;curry()&lt;/tt&gt; and &lt;tt&gt;toSelfCurrying()&lt;/tt&gt;.

Second, this blog's design is the handy work of my colleague Ben Eastaugh (&lt;a href="http://extralogical.net/" rel="nofollow"&gt;extralogical.net&lt;/a&gt;). Funny story, I'd been using this blog template for months before I moved to my current job. A little while after I started, we hired Ben and it emerged he was behind my blog design. Small world.</description>
		<content:encoded><![CDATA[<p>Just to clear up a couple of things: first, as defined in the Haskell language:</p>
<p>&#8220;Currying is the process of transforming a function that takes multiple arguments into a function that takes just a single argument and returns another function if any arguments are still needed.&#8221; - <a href="http://www.haskell.org/haskellwiki/Currying" rel="nofollow">Haskell docs</a></p>
<p>This is what <tt>toSelfCurrying()</tt> does. However, according to Wikipedia:</p>
<p>&#8220;In computer science, currying, invented by Moses Schönfinkel and Gottlob Frege, is the technique of transforming a function that takes multiple arguments into a function that takes a single argument (the other arguments having been specified by the curry).&#8221; - <a href="http://en.wikipedia.org/wiki/Currying" rel="nofollow">Wikipedia</a></p>
<p>So there&#8217;s room for debate. It looks to me (naive as I am) as though Haskell is a special case because all Haskell functions are single-argument functions, so you need to use currying to build multi-argument functions. The discrepancy seems to be over whether pre-set arguments are set with the currying operation. <tt>toSelfCurrying()</tt> is essentially equivalent to currying in Haskell, while Prototype&#8217;s <tt>curry()</tt> is more in tune with the Wikipedia definition, taking into account JavaScript&#8217;s flexibility. Given that the word &#8216;currying&#8217; is a reference to Haskell B. Curry, I&#8217;m inclined to side with the Haskell definition of currying, while referring to Prototype&#8217;s <tt>curry()</tt> as partial application. Apart from anything, <tt>partial()</tt> and <tt>curry()</tt> just seem like better nomenclature than <tt>curry()</tt> and <tt>toSelfCurrying()</tt>.</p>
<p>Second, this blog&#8217;s design is the handy work of my colleague Ben Eastaugh (<a href="http://extralogical.net/" rel="nofollow">extralogical.net</a>). Funny story, I&#8217;d been using this blog template for months before I moved to my current job. A little while after I started, we hired Ben and it emerged he was behind my blog design. Small world.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Morten Barklund</title>
		<link>http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2789</link>
		<dc:creator>Morten Barklund</dc:creator>
		<pubDate>Wed, 06 Feb 2008 21:43:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2789</guid>
		<description>In case automatic trackback does not work properly, I will comment here as well. In my post at http://www.barklund.org/blog/2008/02/06/self-partially-applying-javascript-functions/ I discuss and improve on the above as well as implement it in native JavaScript as well as with the MochiKit framework.

But all in all, a very nice trick and a very nice idea. Thanks for the inspiration :)</description>
		<content:encoded><![CDATA[<p>In case automatic trackback does not work properly, I will comment here as well. In my post at <a href="http://www.barklund.org/blog/2008/02/06/self-partially-applying-javascript-functions/" rel="nofollow">http://www.barklund.org/blog/2008/02/06/self-partially-applying-javascript-functions/</a> I discuss and improve on the above as well as implement it in native JavaScript as well as with the MochiKit framework.</p>
<p>But all in all, a very nice trick and a very nice idea. Thanks for the inspiration <img src='http://blog.jcoglan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephan Schmidt</title>
		<link>http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2787</link>
		<dc:creator>Stephan Schmidt</dc:creator>
		<pubDate>Wed, 06 Feb 2008 18:01:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2787</guid>
		<description>Very nice. And I like the picture and color of your blog

Peace
-stephan</description>
		<content:encoded><![CDATA[<p>Very nice. And I like the picture and color of your blog</p>
<p>Peace<br />
-stephan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2786</link>
		<dc:creator>James</dc:creator>
		<pubDate>Wed, 06 Feb 2008 17:35:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2786</guid>
		<description>Ricardo, thanks for the link. Very helpful, so much so that I actually understood it without ever having used Haskell. Trouble is, Prototype's curry() method is really partial application, but it's taken the name so I needed to call my method something else.</description>
		<content:encoded><![CDATA[<p>Ricardo, thanks for the link. Very helpful, so much so that I actually understood it without ever having used Haskell. Trouble is, Prototype&#8217;s curry() method is really partial application, but it&#8217;s taken the name so I needed to call my method something else.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ricardo Herrmann</title>
		<link>http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2785</link>
		<dc:creator>Ricardo Herrmann</dc:creator>
		<pubDate>Wed, 06 Feb 2008 16:52:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2785</guid>
		<description>Indeed, this is partial application, not currying. Check http://www.haskell.org/haskellwiki/Currying for a quick and nice explanation</description>
		<content:encoded><![CDATA[<p>Indeed, this is partial application, not currying. Check <a href="http://www.haskell.org/haskellwiki/Currying" rel="nofollow">http://www.haskell.org/haskellwiki/Currying</a> for a quick and nice explanation</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: HarryHunt</title>
		<link>http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2782</link>
		<dc:creator>HarryHunt</dc:creator>
		<pubDate>Wed, 06 Feb 2008 09:00:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2782</guid>
		<description>This is pretty cool! Technically speaking, I think this is "partial application" though and not currying.</description>
		<content:encoded><![CDATA[<p>This is pretty cool! Technically speaking, I think this is &#8220;partial application&#8221; though and not currying.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abhijith</title>
		<link>http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2781</link>
		<dc:creator>Abhijith</dc:creator>
		<pubDate>Wed, 06 Feb 2008 05:48:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2781</guid>
		<description>Sweet!. Javascript never seizes to surprise me. Very neat hack!</description>
		<content:encoded><![CDATA[<p>Sweet!. Javascript never seizes to surprise me. Very neat hack!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Goodman</title>
		<link>http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2779</link>
		<dc:creator>Peter Goodman</dc:creator>
		<pubDate>Wed, 06 Feb 2008 03:53:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2779</guid>
		<description>Interesting! You have implemented the curry() function in javascript. Now, can you implement uncurry?</description>
		<content:encoded><![CDATA[<p>Interesting! You have implemented the curry() function in javascript. Now, can you implement uncurry?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cwmonkey</title>
		<link>http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2778</link>
		<dc:creator>cwmonkey</dc:creator>
		<pubDate>Wed, 06 Feb 2008 02:01:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-2778</guid>
		<description>You, sir, are the JavaScript devil. Nice work.</description>
		<content:encoded><![CDATA[<p>You, sir, are the JavaScript devil. Nice work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RStankov</title>
		<link>http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-1948</link>
		<dc:creator>RStankov</dc:creator>
		<pubDate>Wed, 12 Dec 2007 09:14:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jcoglan.com/2007/12/12/self-currying-javascript-functions/#comment-1948</guid>
		<description>:) super cool hack. This shows the power of Javascript.</description>
		<content:encoded><![CDATA[<p> <img src='http://blog.jcoglan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> super cool hack. This shows the power of Javascript.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
