I'm not sure if this will actually be useful to you, but the closest thing I can think of is this. Type E. G: scala> class A { val l: Listthis.
Type = Nil } defined class A scala> new A(). L res3: ListA = List() scala> class B extends A defined class B scala> new B(). L res4: ListB = List().
I'm not sure if this will actually be useful to you, but the closest thing I can think of is this.type. E. G: scala> class A { val l: Listthis.
Type = Nil } defined class A scala> new A(). L res3: ListA = List() scala> class B extends A defined class B scala> new B(). L res4: ListB = List().
4 I don't think "this. Type" is what is called for here though. "this.
Type" is a singleton type; it is the type of "this" instance only. Try as you may, the valid element "Listthis. Type" can contain is "this".
– Walter Chang Oct 19 '09 at 10:09 Yes, you are right. I was trying to remember exactly how it worked. – Lachlan Oct 19 '09 at 12:29.
The this keyword in Scala is more or less equivalent. When developing extensible software it is sometimes handy to declare the type of the value this explicitly: Explicitly Typed Self References in Scala scala-lang.org/node/124.
The singleton types and ETSR's do not solve the problem. I myself was looking for just the same feature in Scala, but apparently it lacks the so-called self-type annotations. There are circumstances where such self-type annotations could be very useful.
Consider an example (adapted from Circular type parameters question example): // we want a container that can store elements trait ContainerE But that's not all. Now suppose you have some sort of an ActiveRecord pattern in mind, and you want to add the method save to Element, which just delegates to it's container's add method. Surprisingly, it is not that easy: trait ElementE Add(this) // won't compile } found : ElementE required: E Intuitively, we have a few options here: make add method accept ElementE instead of E; cast this to ElementE.
None of these options are satisfactory, just because of the fact that E is not the same as ElementE (implementations are not forced to use self-bound type parameters). The only way I see of solving this problem is to have that self-type concept in Scala (let's suppose we have it in our favorite language): trait ContainerE Add(this) // ... and this would be possible, too, ... def container: Containerthis // ... if only we could do this } If the compiler could treat this (or maybe another keyword), when it is used inside square brackets, as the type of the actual implementation (i.e. The same type as the result of obj.
GetClass), then the problems would disappear.P.S.May someone consider including this stuff into Scala wishlist? Unfortunately, I don't know, how hard it is to implement such logic since there could be the problems with the notorious JVM's erasure.P.P.S. Or maybe there is some another Scala-way I'm unaware of?
The singleton types and ETSR's do not solve the problem. I myself was looking for just the same feature in Scala, but apparently it lacks the so-called self-type annotations. There are circumstances where such self-type annotations could be very useful.
Let's say you put that into a library. It is allright and everything works quite as expected. The only thing that concerns is that a library consumer is supposed to use the self-bound type parameter (#1 in the code).
But that's not all. Now suppose you have some sort of an ActiveRecord pattern in mind, and you want to add the method save to Element, which just delegates to it's container's add method.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.