Reputation: 3390
Martin Odersky mentioned that they introduced compound and intersection types in dotty. On his slides there were two pictures representing the difference in upper and lower bounds for old and new type system.
This is the old one:
This is the new one:
Can someone explain what actually upper bound
for T <: U
means? Why it's infinite for current version of scala? How it would be differ for T >: U
for example.
Upvotes: 0
Views: 219
Reputation: 51648
If T <: U
(i.e. T
is a subtype of U
or U
is a supertype of T
) then U
is an upper bound for T
and T
is a lower bound for U
.
In Scala 2
T with U <: T
T with U <: U
U with T <: T
U with T <: U
In Dotty
T & U =:= U & T
T | U =:= U | T
T & U <: T
T & U <: U
T <: T | U
U <: T | U
If T <: U
then
T with U =:= T
T & U =:= T
T | U =:= U
If T >: U
then U <: T
and vice versa
T with U =:= U
T & U =:= U
T | U =:= T
In Scala 2 if T
and U
are from different inheritance hierarchies (or more precisely, subtyping hierarchies) then the best what can be said is
T <: Any
U <: Any
In this sense upper bound is infinite.
Upvotes: 1