gclaramunt | 2 Feb 2008 00:52
Picon

Re: A Tour of Scala: Explicitly Typed Self References


If you use "self: Node with NodeIntf =>" then the line "protected def
newNode: Node = new NodeImpl" doesn't compile. Anyway, seems that the
example is fixed now.
What advantages did you saw in using "self: Node with NodeIntf =>" ?

Thanks !!
Gabriel
http://gabrielsw.blogspot.com

Matt Hellige wrote:
> 
> Not quite. Probably it should be:
>   class NodeImpl {
>     self: Node with NodeIntf =>
> (Just change the original "extends" to "with".) Your version might
> also work, in this example (I haven't looked at the sample code in
> detail). In some specific cases, it's possible to write it either way,
> but in many cases, the difference matters.
> 
> Hope that helps...
> Matt
> 
> On Jan 30, 2008 7:01 PM, Gabriel Claramunt <gclaramunt <at> bellsouth.net>
> wrote:
>> Question:
>> In the Scala tour at the website
>> (http://www.scala-lang.org/intro/selfrefs.html).
>> The following code doesn't compile:
>> abstract class DirectedGraph extends Graph {
>>   ...
>>   class NodeImpl {
>>     self: Node extends NodeIntf =>
>>     def connectWith(node: Node): Edge = {
>>       val edge = newEdge(this, node)  // now legal
>>       edges = edge :: edges
>>       edge
>>     }
>>   }
>>   ...
>> }But it compiles if I change it to:
>>   ...
>>   class NodeImpl extends NodeIntf{
>>     self: Node  =>
>>   ...The second form is the right one?Gabriel
>> Claramunthttp://gabrielsw.blogspot.com
>>
>>
> 
> 
> 
> -- 
> Matt Hellige / matt <at> immute.net
> http://matt.immute.net
> 
> 

--

-- 
View this message in context: http://www.nabble.com/-scala--Scala-BoF-at-EclipseCon--tp15195682p15236446.html
Sent from the Scala mailing list archive at Nabble.com.


Gmane