- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
an open letter to scalac
scalac, I have a burning question for you:
class A {
// Why can't I get my hands on "MyType", if I want to write:
// def otherMe: MyType
// You know you can do this, scalac! I will prove it to you:
def f = this
}
class B extends A { override def f = this }
class C extends B { override def f = this }
class D[T, U, V] extends C { override def f = this }
trait Q { self: C => override def f = this }
object Test {
def x1 = new A f
def x2 = new B f
def x3 = new C f
def x4 = new D[String, Int, List[Int]] f
def x5 = new C with Q { }
// Our mutual buddy scalap says:
//
// def x1 : A = { /* compiled code */ }
// def x2 : B = { /* compiled code */ }
// def x3 : C = { /* compiled code */ }
// def x4 : D[scala.Predef.String, scala.Int, scala.List[scala.Int]]
= { /* compiled code */ }
// def x5 : C with Q = { /* compiled code */ }
//
// and:
//
// class C extends B with scala.ScalaObject {
// override def f : C = { /* compiled code */ }
// }
// class D[T, U, V] extends C with scala.ScalaObject {
// override def f : D[T, U, V] = { /* compiled code */ }
// }
// trait Q extends java.lang.Object with scala.ScalaObject {
// override def f : Q with C = { /* compiled code */ }
// }
}
// See? You know exactly what I'm asking for, scalac.
// You even came up with "C with Q" for god's sake!










Re: an open letter to scalac
This is a huge pain in the ass when using traits that return a modified copy of themselves. At the very least there should be a heavy documented standard way to deal with this scenario. But given that you have to do this all the time when combining immutability with inheritance, language support would be really welcome.
On Sat, Dec 17, 2011 at 10:07 PM, Paul Phillips <paulp [at] improving [dot] org> wrote:
Re: an open letter to scalac
+1
Am 18.12.2011 11:16, schrieb Rüdiger Klaehn:
Re: an open letter to scalac
Minor bug:
On Sat, Dec 17, 2011 at 19:07, Paul Phillips wrote:
> def x5 = new C with Q { }
>
> // See? You know exactly what I'm asking for, scalac.
> // You even came up with "C with Q" for god's sake!
Because f wasn't called in this case.
Re: an open letter to scalac
On Sat, Dec 17, 2011 at 6:02 PM, Daniel Sobral wrote:
> Because f wasn't called in this case.
Oops. Well I'm happy to report it's the same when calling f. (If we
can forgive "Q with C" instead of "C with Q".)
object Test {
def x1 = new A f
def x2 = new B f
def x3 = new C f
def x4 = new D[String, Int, List[Int]] f
def x5 = new C with Q { } f
}
object Test extends java.lang.Object with scala.ScalaObject {
def this() = { /* compiled code */ }
def x1 : A = { /* compiled code */ }
def x2 : B = { /* compiled code */ }
def x3 : C = { /* compiled code */ }
def x4 : D[scala.Predef.String, scala.Int, scala.List[scala.Int]] =
{ /* compiled code */ }
def x5 : Q with C = { /* compiled code */ }
}
Re: an open letter to scalac
On Sat, Dec 17, 2011 at 9:07 PM, Paul Phillips wrote:
> scalac, I have a burning question for you:
>
> class A {
> // Why can't I get my hands on "MyType", if I want to write:
> // def otherMe: MyType
> // You know you can do this, scalac! I will prove it to you:
> def f = this
> }
+ѡ
Cheers,
Miles
Re: an open letter to scalac
Am 17.12.2011 23:22, schrieb Miles Sabin:
> On Sat, Dec 17, 2011 at 9:07 PM, Paul Phillips wrote:
>> scalac, I have a burning question for you:
>>
>> class A {
>> // Why can't I get my hands on "MyType", if I want to write:
>> // def otherMe: MyType
>> // You know you can do this, scalac! I will prove it to you:
>> def f = this
>> }
> +ѡ
>
> Cheers,
>
>
> Miles
>
this might be stupid, but i always used "this.type" as a return type.
why doesn't that work for you?
Re: an open letter to scalac
On Sun, Dec 18, 2011 at 8:12 AM, HamsterofDeath wrote:
> Am 17.12.2011 23:22, schrieb Miles Sabin:
>> On Sat, Dec 17, 2011 at 9:07 PM, Paul Phillips wrote:
>>> scalac, I have a burning question for you:
>>>
>>> class A {
>>> // Why can't I get my hands on "MyType", if I want to write:
>>> // def otherMe: MyType
>>> // You know you can do this, scalac! I will prove it to you:
>>> def f = this
>>> }
>
> this might be stupid, but i always used "this.type" as a return type.
> why doesn't that work for you?
this.type is much too precise. In all of the cases where you see the
kind of encoding that Paul exhibited what's wanted is the least
non-singleton type that bounds this.type.
Cheers,
Miles
Re: an open letter to scalac