I finally have a definitive answer to the question of why MyNode is needed.
Consider the following, simplified, version of the LinkedList classes I posed,
class C<X> { class N { } }
class D: C<D.N> { }
This is really an obfuscated form of
class N<X> { }
class C<X> { }
class D: C<N<?>> { }
where ? needs to be replaced by an infinite list if N<N<...>>. In other
words, I am trying to define a type directly in terms of itself, a
T where T=N<T>. This is not
allowed. An additional type is required to break the cycle, such as
M in,
class M: N<M> { }
Then I can write,
class D: C<M> { }
So, there we have it, MyNode is necessary to avoid defining
a type directly in terms
of itself. The unobfuscated version makes this much more clear.
MyNode serves the same role as M
does above.
Thanks again to Andrew
for taking the time to beat this into my thick skull.
Linked List VI: Recursion - see recursion
I finally have a definitive answer to the question of why MyNode is needed. Consider the following, simplified, version of the LinkedList classes I posed,
class C<X> { class N { } } class D: C<D.N> { }This is really an obfuscated form of
class N<X> { } class C<X> { } class D: C<N<?>> { }where ? needs to be replaced by an infinite list if N<N<...>>. In other words, I am trying to define a type directly in terms of itself, a T where T=N<T>. This is not allowed. An additional type is required to break the cycle, such as M in,
class M: N<M> { }Then I can write,
class D: C<M> { }So, there we have it, MyNode is necessary to avoid defining a type directly in terms of itself. The unobfuscated version makes this much more clear. MyNode serves the same role as M does above.
Thanks again to Andrew for taking the time to beat this into my thick skull.
10:06 AM | Comments [1] | #Programming
09/26/2006 1:54 AM
Ah - but of course ;). It was recursive after all.Thanks for digging! Nice to have the curiosity satiesfied.
/Hallvard
Hallvard Vassbotn | http://hallvards.blogspot.com/