<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Function Currying in Scala</title>
	<atom:link href="http://www.codecommit.com/blog/scala/function-currying-in-scala/feed" rel="self" type="application/rss+xml" />
	<link>http://www.codecommit.com/blog/scala/function-currying-in-scala</link>
	<description>(permanently in beta)</description>
	<lastBuildDate>Mon, 09 Jan 2012 20:21:24 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ant Kutschera</title>
		<link>http://www.codecommit.com/blog/scala/function-currying-in-scala/comment-page-1#comment-5497</link>
		<dc:creator>Ant Kutschera</dc:creator>
		<pubDate>Mon, 09 Jan 2012 20:21:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/function-currying-in-scala#comment-5497</guid>
		<description>Hi,

Nice article.  Perhaps a better application of currying is in writing your own control structures, as described in Programming in Scala, 2nd Edition, Chapter 9.  Using currying you can write neat things like this, where we no longer have to worry about closing resources, because the control stucture does it for us:

    val f = new File(&quot;c:\\temp\\someFile.txt&quot;)
    
    //looks a little like a for comprehension.  this works, because for functions taking ONE parameter, you can use braces or brackets to call it
    withPrintWriter(f){
      pw =&gt; pw.append(&quot;now it is &quot; + new Date() + &quot;\r\n&quot;)
    }

The function is defined as a curried function:

    def withPrintWriter(file: File)(op: PrintWriter =&gt; Unit) {
    	val writer = new PrintWriter(file)
    	try {
    		op(writer)
    	} finally {
    		writer.close()
    	}
    }</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Nice article.  Perhaps a better application of currying is in writing your own control structures, as described in Programming in Scala, 2nd Edition, Chapter 9.  Using currying you can write neat things like this, where we no longer have to worry about closing resources, because the control stucture does it for us:</p>
<p>    val f = new File(&#8220;c:\\temp\\someFile.txt&#8221;)</p>
<p>    //looks a little like a for comprehension.  this works, because for functions taking ONE parameter, you can use braces or brackets to call it<br />
    withPrintWriter(f){<br />
      pw =&gt; pw.append(&#8220;now it is &#8221; + new Date() + &#8220;\r\n&#8221;)<br />
    }</p>
<p>The function is defined as a curried function:</p>
<p>    def withPrintWriter(file: File)(op: PrintWriter =&gt; Unit) {<br />
    	val writer = new PrintWriter(file)<br />
    	try {<br />
    		op(writer)<br />
    	} finally {<br />
    		writer.close()<br />
    	}<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: opensas</title>
		<link>http://www.codecommit.com/blog/scala/function-currying-in-scala/comment-page-1#comment-5475</link>
		<dc:creator>opensas</dc:creator>
		<pubDate>Mon, 05 Dec 2011 17:35:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/function-currying-in-scala#comment-5475</guid>
		<description>Excellent article, I&#039;ve understood what currying means reading this http://gleichmann.wordpress.com/2011/12/04/functional-scala-curried-functions-and-spicy-methods/

but this helped me understand why it could be useful...</description>
		<content:encoded><![CDATA[<p>Excellent article, I&#8217;ve understood what currying means reading this <a href="http://gleichmann.wordpress.com/2011/12/04/functional-scala-curried-functions-and-spicy-methods/" rel="nofollow">http://gleichmann.wordpress.com/2011/12/04/functional-scala-curried-functions-and-spicy-methods/</a></p>
<p>but this helped me understand why it could be useful&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anon</title>
		<link>http://www.codecommit.com/blog/scala/function-currying-in-scala/comment-page-1#comment-5441</link>
		<dc:creator>anon</dc:creator>
		<pubDate>Sat, 20 Aug 2011 11:59:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/function-currying-in-scala#comment-5441</guid>
		<description>It&#039;s correct hat strictly speaking Haskell functions can take only one parameter but I hope you understand that that&#039;s more of an implementation detail, i.e. all Haskell functions are inherently curried which has the effect that you can work with function declarations as if they&#039;re taking arbitrary amounts of arguments. No need for crappy workarounds like tuples if you want to pass more than one argument.

Prelude&gt; let add a b = a + b
Prelude&gt; let inc = add 1
Prelude&gt; add 2 3
5
Prelude&gt; inc 3
4

and this works with arbitrary amounts of arguments. and of course this has also has whole-program type inference. 

Prelude&gt; :t add
add :: Num a =&gt; a -&gt; a -&gt; a

Scala, although quite nice and a great choice among the JVM languages, doesn&#039;t even come close to the awesomeness that is Haskell imo.</description>
		<content:encoded><![CDATA[<p>It&#8217;s correct hat strictly speaking Haskell functions can take only one parameter but I hope you understand that that&#8217;s more of an implementation detail, i.e. all Haskell functions are inherently curried which has the effect that you can work with function declarations as if they&#8217;re taking arbitrary amounts of arguments. No need for crappy workarounds like tuples if you want to pass more than one argument.</p>
<p>Prelude&gt; let add a b = a + b<br />
Prelude&gt; let inc = add 1<br />
Prelude&gt; add 2 3<br />
5<br />
Prelude&gt; inc 3<br />
4</p>
<p>and this works with arbitrary amounts of arguments. and of course this has also has whole-program type inference. </p>
<p>Prelude&gt; :t add<br />
add :: Num a =&gt; a -&gt; a -&gt; a</p>
<p>Scala, although quite nice and a great choice among the JVM languages, doesn&#8217;t even come close to the awesomeness that is Haskell imo.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andreas S.</title>
		<link>http://www.codecommit.com/blog/scala/function-currying-in-scala/comment-page-1#comment-5428</link>
		<dc:creator>Andreas S.</dc:creator>
		<pubDate>Sat, 09 Jul 2011 21:31:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/function-currying-in-scala#comment-5428</guid>
		<description>Hi Horst!
Yes both process methods have the same signatures. But the interesting bit is the processEvens function value where he combines a function (add) with the process method so that a new function value. And this only takes one parameter, you create a function with certain &quot;default&quot; behaviour. I think that&#039;s it.</description>
		<content:encoded><![CDATA[<p>Hi Horst!<br />
Yes both process methods have the same signatures. But the interesting bit is the processEvens function value where he combines a function (add) with the process method so that a new function value. And this only takes one parameter, you create a function with certain &#8220;default&#8221; behaviour. I think that&#8217;s it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Horst Makitta</title>
		<link>http://www.codecommit.com/blog/scala/function-currying-in-scala/comment-page-1#comment-4957</link>
		<dc:creator>Horst Makitta</dc:creator>
		<pubDate>Thu, 01 Apr 2010 21:29:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/function-currying-in-scala#comment-4957</guid>
		<description>Well a bit late to the game, but maybe i get an answer?

As a Java-Programmer i am interested in Scala &#039;cause it presents all those functional advanced concepts in a very readable manner (unlike Lisp). Or let&#039;s say in a form that&#039;s much easier to grasp when used to Java.

However i still fail to see what the difference in currying and using partially applied functions is (besides having to specify the types of the underscores): Both appear to return the exact same function signatures.

You example with process, using partially applied functions:
def process[A](filter:A=&gt;Boolean,list:List[A]):List[A] = {
  lazy val recurse = process(filter, _:List[A])
...

Everything else remains the same and it works as expected:
scala&gt; process(even,numbersAsc)
res11: List[Int] = List(2, 4)

scala&gt; process(even,numbersDesc)
res12: List[Int] = List(4, 2)

So what is the reason for the special curryable form?</description>
		<content:encoded><![CDATA[<p>Well a bit late to the game, but maybe i get an answer?</p>
<p>As a Java-Programmer i am interested in Scala &#8217;cause it presents all those functional advanced concepts in a very readable manner (unlike Lisp). Or let&#8217;s say in a form that&#8217;s much easier to grasp when used to Java.</p>
<p>However i still fail to see what the difference in currying and using partially applied functions is (besides having to specify the types of the underscores): Both appear to return the exact same function signatures.</p>
<p>You example with process, using partially applied functions:<br />
def process[A](filter:A=&gt;Boolean,list:List[A]):List[A] = {<br />
  lazy val recurse = process(filter, _:List[A])<br />
&#8230;</p>
<p>Everything else remains the same and it works as expected:<br />
scala&gt; process(even,numbersAsc)<br />
res11: List[Int] = List(2, 4)</p>
<p>scala&gt; process(even,numbersDesc)<br />
res12: List[Int] = List(4, 2)</p>
<p>So what is the reason for the special curryable form?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Landei</title>
		<link>http://www.codecommit.com/blog/scala/function-currying-in-scala/comment-page-1#comment-3314</link>
		<dc:creator>Landei</dc:creator>
		<pubDate>Thu, 20 Mar 2008 09:27:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/function-currying-in-scala#comment-3314</guid>
		<description>Very cool post, you have a new reader :-)</description>
		<content:encoded><![CDATA[<p>Very cool post, you have a new reader <img src='http://www.codecommit.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/scala/function-currying-in-scala/comment-page-1#comment-3313</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Thu, 20 Mar 2008 08:29:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/function-currying-in-scala#comment-3313</guid>
		<description>Very true, but it would still be nice to get the inference whenever possible.</description>
		<content:encoded><![CDATA[<p>Very true, but it would still be nice to get the inference whenever possible.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Florian Hars</title>
		<link>http://www.codecommit.com/blog/scala/function-currying-in-scala/comment-page-1#comment-3312</link>
		<dc:creator>Florian Hars</dc:creator>
		<pubDate>Thu, 20 Mar 2008 07:33:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/function-currying-in-scala#comment-3312</guid>
		<description>The type of the arguments of add5 can&#039;t be inferred in general, because there might be overloaded add methods in scope with argument types (Int, Float, Float) and (Int, Boolean, String). Which one should add(5,_,_) resolve to?</description>
		<content:encoded><![CDATA[<p>The type of the arguments of add5 can&#8217;t be inferred in general, because there might be overloaded add methods in scope with argument types (Int, Float, Float) and (Int, Boolean, String). Which one should add(5,_,_) resolve to?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/scala/function-currying-in-scala/comment-page-1#comment-3308</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Wed, 19 Mar 2008 01:51:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/function-currying-in-scala#comment-3308</guid>
		<description>Yes, I am misusing the term &quot;dynamic programming&quot;.  The problem is that there doesn&#039;t seem to be a very good term to describe that particular concept.  Dynamic typing is close, but insufficient.  Meta-programming perhaps, but meta-programming is possible with entirely static constructs.  We really need a new term which encompasses all of the modern techniques which go along with languages like Ruby and Groovy.</description>
		<content:encoded><![CDATA[<p>Yes, I am misusing the term &#8220;dynamic programming&#8221;.  The problem is that there doesn&#8217;t seem to be a very good term to describe that particular concept.  Dynamic typing is close, but insufficient.  Meta-programming perhaps, but meta-programming is possible with entirely static constructs.  We really need a new term which encompasses all of the modern techniques which go along with languages like Ruby and Groovy.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: abulafia</title>
		<link>http://www.codecommit.com/blog/scala/function-currying-in-scala/comment-page-1#comment-3307</link>
		<dc:creator>abulafia</dc:creator>
		<pubDate>Wed, 19 Mar 2008 00:19:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/function-currying-in-scala#comment-3307</guid>
		<description>Hi, 

i think the term &quot;dynamic programming&quot; is  misused in this article. You probably mean something like dynamic typing but not http://en.wikipedia.org/wiki/Dynamic_programming.

abu</description>
		<content:encoded><![CDATA[<p>Hi, </p>
<p>i think the term &#8220;dynamic programming&#8221; is  misused in this article. You probably mean something like dynamic typing but not <a href="http://en.wikipedia.org/wiki/Dynamic_programming" rel="nofollow">http://en.wikipedia.org/wiki/Dynamic_programming</a>.</p>
<p>abu</p>
]]></content:encoded>
	</item>
</channel>
</rss>

