There are sometimes advantages to using the self type. e.g.
inheritance at that point can change the initialisation and override
orders.
On Tue, Oct 14, 2008 at 7:26 PM, Alex Boisvert <
boisvert@...> wrote:
> I think we're drifting from the original question but if you're looking for
> a way to reduce boilerplate in the original code, it's easier to just extend
> the trait rather than using it as a self-type.
>
> trait B extends A
>
> Aren't self-types useful only if you have some kind of circular dependency
> between the types?
>
> alex
>
> On Tue, Oct 14, 2008 at 2:52 AM, Sean McDirmid <
sean.mcdirmid@...>
> wrote:
>>
>> Easy, just avoid self types:
>>
>> trait B {
>> def self : A
>> protected implicit def coerce(b : this.type) : A = self
>> }
>>
>> They don't work on the outside anyways, so I always role my own. Just
>> remember to close the loop (self = this) when you create a concrete
>> sub-class.
>>
>> Sean
>>
>>
>>
>>
>> On Sun, Oct 12, 2008 at 12:52 AM, Mushtaq Ahmed <
mushtaq.a@...>
>> wrote:
>> >
>> > Given that,
>> >
>> > trait A
>> > trait B {this: A =>}
>> >
>> > Each time we extend B, we need to explicitly specify the self type as A:
>> >
>> > trait C extends B {this: A =>}
>> > trait D extends B {this: A =>}
>> > trait E extends B {this: A =>}
>> >
>> > Can't this repetition be avoided? Shouldn't self type of C, D and E
>> > default
>> > to A unless explicitly specified otherwise? Currently, this gives the
>> > following error:
>> >
>> > trait F extends B
>> > error: illegal inheritance; self-type F does not conform to B's selftype
>> > B
>> > with A
>> >
>> > Regards,
>> > Mushtaq
>> > --
>> > View this message in context:
>> >
http://www.nabble.com/self-type-is-not-inherited-tp19934242p19934242.html>> > Sent from the Scala mailing list archive at Nabble.com.
>> >
>> >
>
>