<?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: Scala Collections for the Easily Bored Part 1: A Tale of Two Flavors</title>
	<atom:link href="http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-1/feed" rel="self" type="application/rss+xml" />
	<link>http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-1</link>
	<description>(permanently in beta)</description>
	<lastBuildDate>Sun, 29 Aug 2010 20:01:44 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Design Pattern</title>
		<link>http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-1/comment-page-1#comment-4940</link>
		<dc:creator>Design Pattern</dc:creator>
		<pubDate>Fri, 19 Feb 2010 19:45:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-1#comment-4940</guid>
		<description>@Ali

In the first example, you do NOT change the immutable Set,
but you do assign a (reference to) new Set to variable jetSet.

In the second example you modify the original set.

Try without the import:
scala&gt; val movieSet = Set(&quot;Hitch&quot;, &quot;Poltegeist&quot;)
movieSet: scala.collection.immutable.Set[java.lang.String] = Set(Hitch, Poltegeist)

scala&gt; movieSet += &quot;Scary Movie&quot;
:6: error: reassignment to val
       movieSet += &quot;Scary Movie&quot;
                ^</description>
		<content:encoded><![CDATA[<p>@Ali</p>
<p>In the first example, you do NOT change the immutable Set,<br />
but you do assign a (reference to) new Set to variable jetSet.</p>
<p>In the second example you modify the original set.</p>
<p>Try without the import:<br />
scala&gt; val movieSet = Set(&#8220;Hitch&#8221;, &#8220;Poltegeist&#8221;)<br />
movieSet: scala.collection.immutable.Set[java.lang.String] = Set(Hitch, Poltegeist)</p>
<p>scala&gt; movieSet += &#8220;Scary Movie&#8221;<br />
:6: error: reassignment to val<br />
       movieSet += &#8220;Scary Movie&#8221;<br />
                ^</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ali</title>
		<link>http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-1/comment-page-1#comment-4930</link>
		<dc:creator>Ali</dc:creator>
		<pubDate>Tue, 02 Feb 2010 12:43:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-1#comment-4930</guid>
		<description>Daniel,

I&#039;m a bit confused about 2 examples in Programming in Scala:

var jetSet = Set (&quot;Boeing&quot;, &quot;Airbus&quot;) //immutable set 
jetSet += &quot;Lear&quot; // but we can still change it?

and this as well:

import scala.collection.mutable.Set
val movieSet = Set(&quot;Hitch&quot;,&quot;Poltegeist&quot;)
movieSet += &quot;Shrek&quot;

What&#039;s the difference between these?</description>
		<content:encoded><![CDATA[<p>Daniel,</p>
<p>I&#8217;m a bit confused about 2 examples in Programming in Scala:</p>
<p>var jetSet = Set (&#8220;Boeing&#8221;, &#8220;Airbus&#8221;) //immutable set<br />
jetSet += &#8220;Lear&#8221; // but we can still change it?</p>
<p>and this as well:</p>
<p>import scala.collection.mutable.Set<br />
val movieSet = Set(&#8220;Hitch&#8221;,&#8221;Poltegeist&#8221;)<br />
movieSet += &#8220;Shrek&#8221;</p>
<p>What&#8217;s the difference between these?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-1/comment-page-1#comment-4919</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Tue, 29 Dec 2009 06:24:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-1#comment-4919</guid>
		<description>Actually, it&#039;s not so much of an irregularity.  Array is a specific implementation of Seq, whereas Set is a generic abstraction.  When you say Set(), the result is an instance of some implementation, but you don&#039;t know which one.  Because Array is just an interface to direct, random-access memory, you can&#039;t have multiple implementations.

In practice, arrays aren&#039;t used all that much in Scala.  Most of the time, I find myself using toArray from some other Seq built in a functional manner, and then only when I have to interact with a legacy Java API which requires raw arrays.</description>
		<content:encoded><![CDATA[<p>Actually, it&#8217;s not so much of an irregularity.  Array is a specific implementation of Seq, whereas Set is a generic abstraction.  When you say Set(), the result is an instance of some implementation, but you don&#8217;t know which one.  Because Array is just an interface to direct, random-access memory, you can&#8217;t have multiple implementations.</p>
<p>In practice, arrays aren&#8217;t used all that much in Scala.  Most of the time, I find myself using toArray from some other Seq built in a functional manner, and then only when I have to interact with a legacy Java API which requires raw arrays.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jeffpk</title>
		<link>http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-1/comment-page-1#comment-4918</link>
		<dc:creator>jeffpk</dc:creator>
		<pubDate>Tue, 29 Dec 2009 03:52:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-1#comment-4918</guid>
		<description>So... whiy is it that, according to Orderksy et al in Programming in Scala...

To get an instance of an array you write:  new Array
But to get an instance of a Set you type:  Set()

This irregularity is truly ugly.</description>
		<content:encoded><![CDATA[<p>So&#8230; whiy is it that, according to Orderksy et al in Programming in Scala&#8230;</p>
<p>To get an instance of an array you write:  new Array<br />
But to get an instance of a Set you type:  Set()</p>
<p>This irregularity is truly ugly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris de Vreeze</title>
		<link>http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-1/comment-page-1#comment-3974</link>
		<dc:creator>Chris de Vreeze</dc:creator>
		<pubDate>Sat, 23 Aug 2008 17:33:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-1#comment-3974</guid>
		<description>Ok, I see what you are getting at. Btw, thanks for your blogs on Scala for Java developers. They are really helpful.</description>
		<content:encoded><![CDATA[<p>Ok, I see what you are getting at. Btw, thanks for your blogs on Scala for Java developers. They are really helpful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-1/comment-page-1#comment-3973</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Sat, 23 Aug 2008 16:38:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-1#comment-3973</guid>
		<description>I chose toSet() as a simple example to show how to use immutable collections in a semi-practical setting.  Obviously you would use something a bit more compact (like your idiom) in the real world.  :-)

As to the problems...  Take a gander at the signature for List#flatMap.  By all rights, its function parameter should be constrained to return a value of type List[B].  However, this is not possible conventionally due to the fact that method parameters vary *contravariantly* and return types vary *covariantly*.  This means that the only sound overriding of the flatMap method would have to define the function parameter to either return Iterable[B] (as in the superclass) or any supertype of Iterable[B].  Very annoying restriction.

Higher kinds allow us to get around this, but Scala&#039;s collections API was built before the introduction of higher-kind inference.  I&#039;m not entirely sure why the collections API hasn&#039;t been rewritten to take advantage of this powerful addition to the type system, but unfortunately that&#039;s the way it is.</description>
		<content:encoded><![CDATA[<p>I chose toSet() as a simple example to show how to use immutable collections in a semi-practical setting.  Obviously you would use something a bit more compact (like your idiom) in the real world.  <img src='http://www.codecommit.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>As to the problems&#8230;  Take a gander at the signature for List#flatMap.  By all rights, its function parameter should be constrained to return a value of type List[B].  However, this is not possible conventionally due to the fact that method parameters vary *contravariantly* and return types vary *covariantly*.  This means that the only sound overriding of the flatMap method would have to define the function parameter to either return Iterable[B] (as in the superclass) or any supertype of Iterable[B].  Very annoying restriction.</p>
<p>Higher kinds allow us to get around this, but Scala&#8217;s collections API was built before the introduction of higher-kind inference.  I&#8217;m not entirely sure why the collections API hasn&#8217;t been rewritten to take advantage of this powerful addition to the type system, but unfortunately that&#8217;s the way it is.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris de Vreeze</title>
		<link>http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-1/comment-page-1#comment-3972</link>
		<dc:creator>Chris de Vreeze</dc:creator>
		<pubDate>Sat, 23 Aug 2008 12:40:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-1#comment-3972</guid>
		<description>Frankly, I still fail to see the problems with Scala collections. In your example, you could have directly written:
val nameSet = Set() ++ names
Such idioms to convert between different types of collections are not so bad, right? You are undoubtedly aware of this, so I&#039;m surprised you did not mention it.</description>
		<content:encoded><![CDATA[<p>Frankly, I still fail to see the problems with Scala collections. In your example, you could have directly written:<br />
val nameSet = Set() ++ names<br />
Such idioms to convert between different types of collections are not so bad, right? You are undoubtedly aware of this, so I&#8217;m surprised you did not mention it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-1/comment-page-1#comment-3845</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Mon, 21 Jul 2008 18:16:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-1#comment-3845</guid>
		<description>Yeah, no arguments here.  :-)  To be honest l, I really don&#039;t understand why Scala&#039;s collections are so constrained.  The type system can certainly handle a better design (as your work with Scalaz shows).  Hopefully, the LAMP team will take some inspiration from you and fix the defects in a future release.

With that said, it&#039;s really not all that bad for practical purposes.  Obviously, it&#039;s annoying that methods like map work on Iterable and not the specific subtype.  In normal usage, however, it isn&#039;t really a big deal.  If nothing else, even crippled Scala collections are far more powerful than their Java counterparts.  :-)</description>
		<content:encoded><![CDATA[<p>Yeah, no arguments here.  <img src='http://www.codecommit.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   To be honest l, I really don&#8217;t understand why Scala&#8217;s collections are so constrained.  The type system can certainly handle a better design (as your work with Scalaz shows).  Hopefully, the LAMP team will take some inspiration from you and fix the defects in a future release.</p>
<p>With that said, it&#8217;s really not all that bad for practical purposes.  Obviously, it&#8217;s annoying that methods like map work on Iterable and not the specific subtype.  In normal usage, however, it isn&#8217;t really a big deal.  If nothing else, even crippled Scala collections are far more powerful than their Java counterparts.  <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: Tony Morris</title>
		<link>http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-1/comment-page-1#comment-3843</link>
		<dc:creator>Tony Morris</dc:creator>
		<pubDate>Mon, 21 Jul 2008 08:58:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-1#comment-3843</guid>
		<description>&quot;Fortunately, Scala’s mutable collections have an almost identical interface to its immutable collections.&quot;

This is one of the reasons that abstracting over a type constructor can bring great rewards without the repetition. Frankly, I&#039;m very unimpressed with the core Scala library; oh except for scala.Either of course; that was written by a really handsome bloke :)

I have some libraries that abstract over type constructors in Scalaz 2, but I have rewritten it all for Scalaz 3 (hoping to release this week) with some much better examples. This defers the choice of whether you wish to use mutable or immutable data types in your own code.

See Monad, Functor, Applicative, MonadPlus, MonadEmpty, Foldable, etc.</description>
		<content:encoded><![CDATA[<p>&#8220;Fortunately, Scala’s mutable collections have an almost identical interface to its immutable collections.&#8221;</p>
<p>This is one of the reasons that abstracting over a type constructor can bring great rewards without the repetition. Frankly, I&#8217;m very unimpressed with the core Scala library; oh except for scala.Either of course; that was written by a really handsome bloke <img src='http://www.codecommit.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I have some libraries that abstract over type constructors in Scalaz 2, but I have rewritten it all for Scalaz 3 (hoping to release this week) with some much better examples. This defers the choice of whether you wish to use mutable or immutable data types in your own code.</p>
<p>See Monad, Functor, Applicative, MonadPlus, MonadEmpty, Foldable, etc.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
