<?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 for Java Refugees Part 5: Traits and Types</title>
	<atom:link href="http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5/feed" rel="self" type="application/rss+xml" />
	<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5</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: anonymous</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5/comment-page-1#comment-5362</link>
		<dc:creator>anonymous</dc:creator>
		<pubDate>Sun, 20 Mar 2011 00:40:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5#comment-5362</guid>
		<description>I think we may have different definitions of &quot;multiple inheritance.&quot;  I think that Scala has limited multiple inheritance, although it is not full MI, via traits, because it can inherit method implementation from multiple sources (traits).</description>
		<content:encoded><![CDATA[<p>I think we may have different definitions of &#8220;multiple inheritance.&#8221;  I think that Scala has limited multiple inheritance, although it is not full MI, via traits, because it can inherit method implementation from multiple sources (traits).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shelby Moore III</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5/comment-page-1#comment-5332</link>
		<dc:creator>Shelby Moore III</dc:creator>
		<pubDate>Mon, 28 Feb 2011 00:48:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5#comment-5332</guid>
		<description>@anonymous
I suggest re-read my prior comments more carefully, and study how Scala&#039;s mixins really work and what they really do:

http://copute.com/dev/docs/Copute/ref/class.html#Inheritance (review the references cited there for Scala too)

There is no multiple inheritance.  All implementation in traits are folded into the single-inheritance on per member basis and it is called &quot;linearization&quot;. And any duplicate members MUST be resolved by the subclass.</description>
		<content:encoded><![CDATA[<p>@anonymous<br />
I suggest re-read my prior comments more carefully, and study how Scala&#8217;s mixins really work and what they really do:</p>
<p><a href="http://copute.com/dev/docs/Copute/ref/class.html#Inheritance" rel="nofollow">http://copute.com/dev/docs/Copute/ref/class.html#Inheritance</a> (review the references cited there for Scala too)</p>
<p>There is no multiple inheritance.  All implementation in traits are folded into the single-inheritance on per member basis and it is called &#8220;linearization&#8221;. And any duplicate members MUST be resolved by the subclass.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anonymous</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5/comment-page-1#comment-5331</link>
		<dc:creator>anonymous</dc:creator>
		<pubDate>Sun, 27 Feb 2011 23:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5#comment-5331</guid>
		<description>@shelby:

Err...what?

Yes, the compiler *does* do some clever tricks to fold MI into the inheritance chain.  So?

If you really wanted to, you could do the same thing for a language with &#039;&#039;no&#039;&#039; proper implementation inheritance.

       interface Foo {
          Foo clone();
          Foo next();
          Foo plusBy(int n);
       }
       class Foo$class {
           static Foo plusBy(Foo this_t, int n) {
                Foo res = null;
                for (i = 0; i &lt; n; i++) res = res.next();
                return res
            }
       }
       class Bar implements Foo {
            private int i;
            Bar(int i) {this.i = i}
            Foo clone() { return this; }
            Foo next() {return new Bar(i+1) }
            Foo plusBy(int n) {return Foo$class.plusBy(this, n)}
        }


However, that&#039;s really not the point.  If there was a compiler that turned Scala into C++, then traits could become Multiple Inheritance proper.  Yes, Scala doesn&#039;t have &lt;em&gt;full&lt;/em&gt; MI, but it does have some.  Heck, even Java has some, with multiple interface inheritance.

Actually, come to think of it, what you said isn&#039;t strictly true.  The &lt;em&gt;implementation&lt;/em&gt; inheritance is folded away into the single-inheritance chain--well, actually, it&#039;s usually folded into the class itself, but that&#039;s not the point--but the &lt;em&gt;interface&lt;/em&gt; of the trait is inherited as normal, and &lt;em&gt;more than one interface may be inherited&lt;/em&gt;.  Scala isn&#039;t a strictly MI language, but &lt;em&gt;don&#039;t&lt;/em&gt; call it a Single-Inheritance one.</description>
		<content:encoded><![CDATA[<p>@shelby:</p>
<p>Err&#8230;what?</p>
<p>Yes, the compiler *does* do some clever tricks to fold MI into the inheritance chain.  So?</p>
<p>If you really wanted to, you could do the same thing for a language with &#8221;no&#8221; proper implementation inheritance.</p>
<p>       interface Foo {<br />
          Foo clone();<br />
          Foo next();<br />
          Foo plusBy(int n);<br />
       }<br />
       class Foo$class {<br />
           static Foo plusBy(Foo this_t, int n) {<br />
                Foo res = null;<br />
                for (i = 0; i &lt; n; i++) res = res.next();<br />
                return res<br />
            }<br />
       }<br />
       class Bar implements Foo {<br />
            private int i;<br />
            Bar(int i) {this.i = i}<br />
            Foo clone() { return this; }<br />
            Foo next() {return new Bar(i+1) }<br />
            Foo plusBy(int n) {return Foo$class.plusBy(this, n)}<br />
        }</p>
<p>However, that&#8217;s really not the point.  If there was a compiler that turned Scala into C++, then traits could become Multiple Inheritance proper.  Yes, Scala doesn&#8217;t have <em>full</em> MI, but it does have some.  Heck, even Java has some, with multiple interface inheritance.</p>
<p>Actually, come to think of it, what you said isn&#8217;t strictly true.  The <em>implementation</em> inheritance is folded away into the single-inheritance chain&#8211;well, actually, it&#8217;s usually folded into the class itself, but that&#8217;s not the point&#8211;but the <em>interface</em> of the trait is inherited as normal, and <em>more than one interface may be inherited</em>.  Scala isn&#8217;t a strictly MI language, but <em>don&#8217;t</em> call it a Single-Inheritance one.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shelby Moore III</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5/comment-page-1#comment-5286</link>
		<dc:creator>Shelby Moore III</dc:creator>
		<pubDate>Sun, 13 Feb 2011 09:24:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5#comment-5286</guid>
		<description>@Cedric

Don&#039;t conflate some programmer&#039;s insufficient separation-of-concerns in the design of a trait with the Diamond Problem.The Diamond Problem is a specific problem of how to resolve multiple inheritance name spaces (scope).

Also please realize that Scala is a single-inheritance language, with the apparency of multiple inheritance of traits. In reality, traits get folded into that single-inheritance chain in a specific order and are NOT multiply inherited.</description>
		<content:encoded><![CDATA[<p>@Cedric</p>
<p>Don&#8217;t conflate some programmer&#8217;s insufficient separation-of-concerns in the design of a trait with the Diamond Problem.The Diamond Problem is a specific problem of how to resolve multiple inheritance name spaces (scope).</p>
<p>Also please realize that Scala is a single-inheritance language, with the apparency of multiple inheritance of traits. In reality, traits get folded into that single-inheritance chain in a specific order and are NOT multiply inherited.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shelby Moore III</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5/comment-page-1#comment-5285</link>
		<dc:creator>Shelby Moore III</dc:creator>
		<pubDate>Sun, 13 Feb 2011 09:14:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5#comment-5285</guid>
		<description>typo: I meant &quot;...have to resolved by the subclass...&quot;</description>
		<content:encoded><![CDATA[<p>typo: I meant &#8220;&#8230;have to resolved by the subclass&#8230;&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shelby Moore III</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5/comment-page-1#comment-5284</link>
		<dc:creator>Shelby Moore III</dc:creator>
		<pubDate>Sun, 13 Feb 2011 09:12:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5#comment-5284</guid>
		<description>@Cedric

You missed the point of mixins. They completely solve the diamond problem because only duplicate methods which are from the EXACT SAME trait are resolved automatically. Any duplicates from different traits have to be resolved by the superclass in the single-inheritance chain (i.e. analogous to &quot;Class::&quot; in C++).

You can&#039;t do &quot;Class::&quot; specific method call from a trait (you must use the less specific &quot;super.&quot; instead), this because mixin order can insert an mixin in middle of the inheritance hierarchy of another mixin. For example, given mixin A (B) and mixin C (B), then mixin D (C,A) would effectively cause mixin C (A,B), because the B in mixin C (B) is already in the inheritance tree of mixin A (B), and thus not repeated. A more detailed explanation can be found at top, left of page 7 in the Super subsection of the 2.2 Modular Mixin Composition section of Scalable Component Abstractions, Odersky &amp; Zenger, Proceedings of OOPSLA 2005, San Diego, October 2005.

http://www.scala-lang.org/sites/default/files/odersky/ScalableComponent.pdf

So I want you to realized that &quot;Class::&quot; specific method invocation can never be as flexible as mixins.

I studied this deeply for the design of my Copute language.</description>
		<content:encoded><![CDATA[<p>@Cedric</p>
<p>You missed the point of mixins. They completely solve the diamond problem because only duplicate methods which are from the EXACT SAME trait are resolved automatically. Any duplicates from different traits have to be resolved by the superclass in the single-inheritance chain (i.e. analogous to &#8220;Class::&#8221; in C++).</p>
<p>You can&#8217;t do &#8220;Class::&#8221; specific method call from a trait (you must use the less specific &#8220;super.&#8221; instead), this because mixin order can insert an mixin in middle of the inheritance hierarchy of another mixin. For example, given mixin A (B) and mixin C (B), then mixin D (C,A) would effectively cause mixin C (A,B), because the B in mixin C (B) is already in the inheritance tree of mixin A (B), and thus not repeated. A more detailed explanation can be found at top, left of page 7 in the Super subsection of the 2.2 Modular Mixin Composition section of Scalable Component Abstractions, Odersky &amp; Zenger, Proceedings of OOPSLA 2005, San Diego, October 2005.</p>
<p><a href="http://www.scala-lang.org/sites/default/files/odersky/ScalableComponent.pdf" rel="nofollow">http://www.scala-lang.org/sites/default/files/odersky/ScalableComponent.pdf</a></p>
<p>So I want you to realized that &#8220;Class::&#8221; specific method invocation can never be as flexible as mixins.</p>
<p>I studied this deeply for the design of my Copute language.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anonymous</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5/comment-page-1#comment-5170</link>
		<dc:creator>anonymous</dc:creator>
		<pubDate>Fri, 29 Oct 2010 20:53:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5#comment-5170</guid>
		<description>I know that the article is long gone, but:

I think that traits are &lt;em&gt;much&lt;/em&gt; better than interfaces.  Why?  Because you &lt;em&gt;don&#039;t have to use what they provide&lt;/em&gt;, but they give you some useful things.  For example, the Monad trait, provided you implement flatMap[B](fn : A =&gt; M[B]) : M[B], defines the following for you:


     def flatMap[B, That](fn : A =&gt; M[B])(implicit bf : CanBuildFrom[M, B, That]) : That
     // flatMaps, then converts to type That, eg, from Array[T] to List[T], or String, Int...provided you can tell it how to do so with a CanBuildFrom subclass.
     def map[B](fn : A =&gt; B) : M[B]
     def map[B, That](fn : A =&gt; B)(implicit bf : CanBuildFrom[M, B, That]) : That
     // maps, then builds into type That.
     def foreach(fn : A =&gt; Unit) : Unit


Don&#039;t understand any of that?  Good.  You don&#039;t have to, thanks to traits.</description>
		<content:encoded><![CDATA[<p>I know that the article is long gone, but:</p>
<p>I think that traits are <em>much</em> better than interfaces.  Why?  Because you <em>don&#8217;t have to use what they provide</em>, but they give you some useful things.  For example, the Monad trait, provided you implement flatMap[B](fn : A =&gt; M[B]) : M[B], defines the following for you:</p>
<p>     def flatMap[B, That](fn : A =&gt; M[B])(implicit bf : CanBuildFrom[M, B, That]) : That<br />
     // flatMaps, then converts to type That, eg, from Array[T] to List[T], or String, Int&#8230;provided you can tell it how to do so with a CanBuildFrom subclass.<br />
     def map[B](fn : A =&gt; B) : M[B]<br />
     def map[B, That](fn : A =&gt; B)(implicit bf : CanBuildFrom[M, B, That]) : That<br />
     // maps, then builds into type That.<br />
     def foreach(fn : A =&gt; Unit) : Unit</p>
<p>Don&#8217;t understand any of that?  Good.  You don&#8217;t have to, thanks to traits.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Klaus Loa</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5/comment-page-1#comment-4885</link>
		<dc:creator>Klaus Loa</dc:creator>
		<pubDate>Wed, 26 Aug 2009 13:19:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5#comment-4885</guid>
		<description>&quot;Inspired by a combination of Java’s interfaces and Ruby’s mixins, the designers of Scala have created the trait construct.&quot;

Traits were introduced by Prof.Ducasse at the University of Berne:  http://citeseer.ist.psu.edu/566972.html and first implemented in Squeak Smalltalk. SInce Lausanne is not that far away from Lausanne, where the Scala resides, these people might have exchanged ideas ...</description>
		<content:encoded><![CDATA[<p>&#8220;Inspired by a combination of Java’s interfaces and Ruby’s mixins, the designers of Scala have created the trait construct.&#8221;</p>
<p>Traits were introduced by Prof.Ducasse at the University of Berne:  <a href="http://citeseer.ist.psu.edu/566972.html" rel="nofollow">http://citeseer.ist.psu.edu/566972.html</a> and first implemented in Squeak Smalltalk. SInce Lausanne is not that far away from Lausanne, where the Scala resides, these people might have exchanged ideas &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jaakko</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5/comment-page-1#comment-4828</link>
		<dc:creator>Jaakko</dc:creator>
		<pubDate>Thu, 16 Apr 2009 21:26:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5#comment-4828</guid>
		<description>It&#039;s surprising to see a language which obviously makes it possible to write some very clean looking code and even create DSL&#039;s that look like written english, to use such an ugly operator as :&gt;. That&#039;s definately too perlish for my taste :)

Anyways, great article series. Really got me started on learning Scala.</description>
		<content:encoded><![CDATA[<p>It&#8217;s surprising to see a language which obviously makes it possible to write some very clean looking code and even create DSL&#8217;s that look like written english, to use such an ugly operator as :&gt;. That&#8217;s definately too perlish for my taste <img src='http://www.codecommit.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Anyways, great article series. Really got me started on learning Scala.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5/comment-page-1#comment-3335</link>
		<dc:creator>Martin</dc:creator>
		<pubDate>Fri, 28 Mar 2008 04:08:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-5#comment-3335</guid>
		<description>Hi Daniel,

I&#039;m loving your series of articles thus far. This is the first one I&#039;ve commented on. I wanted to point out that overloading &quot;extends&quot; (in my humble opinion, of course) is no worse than overloading &quot;&amp;lt&quot;. In fact, I&#039;d argue that Scala heavily overloads parens, angle brackets, and many others, much more so than Java does. Flexible? Yes, definitely -- but I wouldn&#039;t say that somehow overloading &quot;extends&quot; (which starts with far fewer meanings than &quot;&amp;lt&quot; and &quot;&amp;gt&quot; do) doesn&#039;t seem *that* bad. I think I&#039;d prefer something else to signify structural type restrictions of a generic type.</description>
		<content:encoded><![CDATA[<p>Hi Daniel,</p>
<p>I&#8217;m loving your series of articles thus far. This is the first one I&#8217;ve commented on. I wanted to point out that overloading &#8220;extends&#8221; (in my humble opinion, of course) is no worse than overloading &#8220;&amp;lt&#8221;. In fact, I&#8217;d argue that Scala heavily overloads parens, angle brackets, and many others, much more so than Java does. Flexible? Yes, definitely &#8212; but I wouldn&#8217;t say that somehow overloading &#8220;extends&#8221; (which starts with far fewer meanings than &#8220;&amp;lt&#8221; and &#8220;&amp;gt&#8221; do) doesn&#8217;t seem *that* bad. I think I&#8217;d prefer something else to signify structural type restrictions of a generic type.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

