<?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: Quick Explanation of Scala&#8217;s (_+_) Syntax</title>
	<atom:link href="http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax/feed" rel="self" type="application/rss+xml" />
	<link>http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax</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: Scott</title>
		<link>http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax/comment-page-1#comment-5463</link>
		<dc:creator>Scott</dc:creator>
		<pubDate>Sat, 22 Oct 2011 06:08:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax#comment-5463</guid>
		<description>Hmm, that underscore is a bit too magic for me.  I prefer the Boost.Lambda way where they&#039;re numbered, so you can tell multiplication _1 * _2 from squaring _1 * _1.</description>
		<content:encoded><![CDATA[<p>Hmm, that underscore is a bit too magic for me.  I prefer the Boost.Lambda way where they&#8217;re numbered, so you can tell multiplication _1 * _2 from squaring _1 * _1.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: greg</title>
		<link>http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax/comment-page-1#comment-5168</link>
		<dc:creator>greg</dc:creator>
		<pubDate>Tue, 26 Oct 2010 14:57:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax#comment-5168</guid>
		<description>I think the premise of this post is a bit misguided. Nobody&#039;s saying that understanding this construct is rocket science.

The problem is that this construct isn&#039;t self-explanatory... even if one has learnt the basic feel of Scala. The more stuff like this a language has, the longer the learning curve is. That&#039;s the issue. You&#039;re asking someone new to find this web page for this cryptic construct, another page for another cryptic construct, etc., etc. Then, you have to find this page again when you forget how this non-intuitive thing works.

It&#039;s a gradient scale but, eventually, newcomers will start to say, &quot;There&#039;s too much arcana here.&quot; The more you put in, the worse it is.

I&#039;m writing a natural language parser for my PhD project (I think Scala&#039;s the best/most fun/most productive language). I want others to extend it eventually. So, I take the time to *type out* certain things in long form so that my intent is clear to another person trying to learn the language and my code *at the same time*, which is inevitable given Scala&#039;s marginal status.

Scala is great but not perfect I wish everyone who likes it didn&#039;t feel the need to defend every part of it, even when they don&#039;t agree, e.g. &quot;The reason I didn’t pick foldLeft is I didn’t want to have to explain how a method signature could have two sets of parentheses. Still seems pretty odd to me, but it’s actually valid syntax.&quot;</description>
		<content:encoded><![CDATA[<p>I think the premise of this post is a bit misguided. Nobody&#8217;s saying that understanding this construct is rocket science.</p>
<p>The problem is that this construct isn&#8217;t self-explanatory&#8230; even if one has learnt the basic feel of Scala. The more stuff like this a language has, the longer the learning curve is. That&#8217;s the issue. You&#8217;re asking someone new to find this web page for this cryptic construct, another page for another cryptic construct, etc., etc. Then, you have to find this page again when you forget how this non-intuitive thing works.</p>
<p>It&#8217;s a gradient scale but, eventually, newcomers will start to say, &#8220;There&#8217;s too much arcana here.&#8221; The more you put in, the worse it is.</p>
<p>I&#8217;m writing a natural language parser for my PhD project (I think Scala&#8217;s the best/most fun/most productive language). I want others to extend it eventually. So, I take the time to *type out* certain things in long form so that my intent is clear to another person trying to learn the language and my code *at the same time*, which is inevitable given Scala&#8217;s marginal status.</p>
<p>Scala is great but not perfect I wish everyone who likes it didn&#8217;t feel the need to defend every part of it, even when they don&#8217;t agree, e.g. &#8220;The reason I didn’t pick foldLeft is I didn’t want to have to explain how a method signature could have two sets of parentheses. Still seems pretty odd to me, but it’s actually valid syntax.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Hicks</title>
		<link>http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax/comment-page-1#comment-3449</link>
		<dc:creator>Tom Hicks</dc:creator>
		<pubDate>Wed, 09 Apr 2008 17:32:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax#comment-3449</guid>
		<description>Daniel wrote:

   &gt;Another way of writing your reduction would be as follows:
   &gt;val mmax = numbers.reduceRight((a:Int, b:Int) =&gt; a.max(b))

Yet another way to phrase this is to use the original function more directly.
Assuming the original author&#039;s function should have been called something
besides &#039;max&#039; to avoid the name collision:

  def mmax (a:Int, b:Int):Int = { if (a&gt;=b) return a ; return b}

  val nums = Array(1, 9, 3, -1, 11, 0)

then the reduceRight could also be applied as:

  nums.reduceRight[Int](mmax(_,_))</description>
		<content:encoded><![CDATA[<p>Daniel wrote:</p>
<p>   &gt;Another way of writing your reduction would be as follows:<br />
   &gt;val mmax = numbers.reduceRight((a:Int, b:Int) =&gt; a.max(b))</p>
<p>Yet another way to phrase this is to use the original function more directly.<br />
Assuming the original author&#8217;s function should have been called something<br />
besides &#8216;max&#8217; to avoid the name collision:</p>
<p>  def mmax (a:Int, b:Int):Int = { if (a&gt;=b) return a ; return b}</p>
<p>  val nums = Array(1, 9, 3, -1, 11, 0)</p>
<p>then the reduceRight could also be applied as:</p>
<p>  nums.reduceRight[Int](mmax(_,_))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax/comment-page-1#comment-3311</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Wed, 19 Mar 2008 04:25:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax#comment-3311</guid>
		<description>Actually, your max function isn&#039;t being called at all in that example.  Scala&#039;s operators are not infix, but actually left-associative method calls.  Another way of writing your reduction would be as follows:

val mmax = numbers.reduceRight((a:Int, b:Int) =&gt; a.max(b))

max(Int) is a method within class RichInt, to which any Int value can be implicitly coerced.

The type parameter for reduceRight is actually what allows us to use the underscores rather than properly typed values.  The trick is that Scala cannot infer the types of the underscores without some sort of specified initial type.  In this case, we&#039;re giving Scala the return type explicitly, so it is able to infer the rest on its own.  I considered using foldLeft instead of reduceLeft, but I thought that the added confusion of a curried function would obscure the point I was trying to make.

This is also a valid way of performing the reduce in the article:

numbers.foldLeft(0)(_+_)</description>
		<content:encoded><![CDATA[<p>Actually, your max function isn&#8217;t being called at all in that example.  Scala&#8217;s operators are not infix, but actually left-associative method calls.  Another way of writing your reduction would be as follows:</p>
<p>val mmax = numbers.reduceRight((a:Int, b:Int) => a.max(b))</p>
<p>max(Int) is a method within class RichInt, to which any Int value can be implicitly coerced.</p>
<p>The type parameter for reduceRight is actually what allows us to use the underscores rather than properly typed values.  The trick is that Scala cannot infer the types of the underscores without some sort of specified initial type.  In this case, we&#8217;re giving Scala the return type explicitly, so it is able to infer the rest on its own.  I considered using foldLeft instead of reduceLeft, but I thought that the added confusion of a curried function would obscure the point I was trying to make.</p>
<p>This is also a valid way of performing the reduce in the article:</p>
<p>numbers.foldLeft(0)(_+_)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stefan Wagner</title>
		<link>http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax/comment-page-1#comment-3310</link>
		<dc:creator>Stefan Wagner</dc:creator>
		<pubDate>Wed, 19 Mar 2008 04:17:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax#comment-3310</guid>
		<description>Minor meta-hint: 
The navigation here shows: 
 
I would expect:
 

bye.</description>
		<content:encoded><![CDATA[<p>Minor meta-hint:<br />
The navigation here shows: </p>
<p>I would expect:</p>
<p>bye.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stefan Wagner</title>
		<link>http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax/comment-page-1#comment-3309</link>
		<dc:creator>Stefan Wagner</dc:creator>
		<pubDate>Wed, 19 Mar 2008 04:15:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax#comment-3309</guid>
		<description>Two remarks:
a) (Question) The [Int] in the first Scala-block:
val sum = numbers.reduceLeft[Int](_+_)
Is it a type information for &#039;reduceLeft&#039;, which is operating on a collection of arbirtrary, but homogen type?
It&#039;s not the return type? 

b) (Not a question) Without operator-overloading or self defined operators, it wasn&#039;t perfect clear to me, that I can use any self defined function instead of +, for example max:
scala&gt; def max (a:Int, b:Int):Int = { if (a&gt;=b)  return a ; return b}
max: (Int,Int)Int

scala&gt; val mmax = numbers.reduceRight[Int](_max_)
:5: error: not found: value _max_
       val mmax = numbers.reduceRight[Int](_max_)
                                           ^
scala&gt; val mmax = numbers.reduceRight[Int](_ max _)
mmax: Int = 5

Ah! :)</description>
		<content:encoded><![CDATA[<p>Two remarks:<br />
a) (Question) The [Int] in the first Scala-block:<br />
val sum = numbers.reduceLeft[Int](_+_)<br />
Is it a type information for &#8216;reduceLeft&#8217;, which is operating on a collection of arbirtrary, but homogen type?<br />
It&#8217;s not the return type? </p>
<p>b) (Not a question) Without operator-overloading or self defined operators, it wasn&#8217;t perfect clear to me, that I can use any self defined function instead of +, for example max:<br />
scala&gt; def max (a:Int, b:Int):Int = { if (a&gt;=b)  return a ; return b}<br />
max: (Int,Int)Int</p>
<p>scala&gt; val mmax = numbers.reduceRight[Int](_max_)<br />
:5: error: not found: value _max_<br />
       val mmax = numbers.reduceRight[Int](_max_)<br />
                                           ^<br />
scala&gt; val mmax = numbers.reduceRight[Int](_ max _)<br />
mmax: Int = 5</p>
<p>Ah! <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: Joerg Gottschling</title>
		<link>http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax/comment-page-1#comment-2961</link>
		<dc:creator>Joerg Gottschling</dc:creator>
		<pubDate>Thu, 14 Feb 2008 07:19:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax#comment-2961</guid>
		<description>Hey, very good post. I like Scala very much, but at last few month, it thought it becames more cryptic from release to release. The real problem is, that the original example does not explain this as good as yours. Now I understand it. Thank you!

Perhaps you could add this to the scala wiki.</description>
		<content:encoded><![CDATA[<p>Hey, very good post. I like Scala very much, but at last few month, it thought it becames more cryptic from release to release. The real problem is, that the original example does not explain this as good as yours. Now I understand it. Thank you!</p>
<p>Perhaps you could add this to the scala wiki.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax/comment-page-1#comment-2663</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Fri, 11 Jan 2008 14:08:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax#comment-2663</guid>
		<description>Yeah, if you think about use-cases, reduceLeft really falls out more commonly useful than foldLeft (though they can be used for the same purpose).  One of the problems with fold is you have to account for some empty space.  Example:

val sqlCols = columnNames.foldLeft(&quot;&quot;)(_ + &quot;, &quot; + _)
assert sqlCols == &quot;, name, id, value&quot;

The leading comma won&#039;t occur if reduce is used.</description>
		<content:encoded><![CDATA[<p>Yeah, if you think about use-cases, reduceLeft really falls out more commonly useful than foldLeft (though they can be used for the same purpose).  One of the problems with fold is you have to account for some empty space.  Example:</p>
<p>val sqlCols = columnNames.foldLeft(&#8220;&#8221;)(_ + &#8220;, &#8221; + _)<br />
assert sqlCols == &#8220;, name, id, value&#8221;</p>
<p>The leading comma won&#8217;t occur if reduce is used.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Chermside</title>
		<link>http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax/comment-page-1#comment-2662</link>
		<dc:creator>Michael Chermside</dc:creator>
		<pubDate>Fri, 11 Jan 2008 03:03:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax#comment-2662</guid>
		<description>Oh, I see. So reduceLeft() is an odd function that treats various elements of the Iterable differently. Let me see if I can write what it does:

 * if the iterable is of length 0, then it throws an exception
 * if the iterable is of length 1, then it returns the single element
 * if the iterable is of length 2+ then it stores the first element in a buffer, then repeatedly performs the binary operation on the buffer and an iterable element, storing the results in the buffer.

Okay, I guess only the FIRST element is being treated differently from the rest. Odd... but probably fairly useful. Handy, for instance, for cases like this:

val sqlCols = columnNames.reduceLeft[String](_ + &quot;, &quot; + _)
val sqlQuery = &quot;SELECT &quot; + sqlCols + &quot; FROM tableName WHERE &quot; + sqlWhere

-- Michael Chermside</description>
		<content:encoded><![CDATA[<p>Oh, I see. So reduceLeft() is an odd function that treats various elements of the Iterable differently. Let me see if I can write what it does:</p>
<p> * if the iterable is of length 0, then it throws an exception<br />
 * if the iterable is of length 1, then it returns the single element<br />
 * if the iterable is of length 2+ then it stores the first element in a buffer, then repeatedly performs the binary operation on the buffer and an iterable element, storing the results in the buffer.</p>
<p>Okay, I guess only the FIRST element is being treated differently from the rest. Odd&#8230; but probably fairly useful. Handy, for instance, for cases like this:</p>
<p>val sqlCols = columnNames.reduceLeft[String](_ + &#8220;, &#8221; + _)<br />
val sqlQuery = &#8220;SELECT &#8221; + sqlCols + &#8221; FROM tableName WHERE &#8221; + sqlWhere</p>
<p>&#8211; Michael Chermside</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark</title>
		<link>http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax/comment-page-1#comment-2659</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Thu, 10 Jan 2008 00:16:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax#comment-2659</guid>
		<description>Nice post, very informative.  This kinda gets into why I think Scala&#039;s a bad idea for some, like for example, Java programmers.  The fact that  _+_  is a function applies the &#039;+&#039; operation to two parametric types is completely obvious if your familiar with SML.  But to an imperative programmer trying to wrap their heads around first class functions AND unfamiliar syntax, well, I expect to see Java programmers writing a lot of Java code in Scala.</description>
		<content:encoded><![CDATA[<p>Nice post, very informative.  This kinda gets into why I think Scala&#8217;s a bad idea for some, like for example, Java programmers.  The fact that  _+_  is a function applies the &#8216;+&#8217; operation to two parametric types is completely obvious if your familiar with SML.  But to an imperative programmer trying to wrap their heads around first class functions AND unfamiliar syntax, well, I expect to see Java programmers writing a lot of Java code in Scala.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

