- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Existential type understanding
Thu, 2011-12-15, 13:40
Hi guys,
I have problems with understanding of existential types.
Original problem is trying to understand how to resolve most specific alternative in this case:
Best regards,
Alexander Podkhalyuzin.
I have problems with understanding of existential types.
object Problem { class A[T] class B extends A[B] def goo[T <: A[T]](y: T): T = y type Y = T forSome {type T <: A[T]} val x: Y = null goo(x) goo[Y](x) }In this code goo(x) is compiled, and goo[Y](x) is not. I want to understand why. My vision is that it is a bug.
Original problem is trying to understand how to resolve most specific alternative in this case:
object Problem { class A[T] class B extends A[B] def goo[T <: A[T]](y: T): T = y def goo[T <: A[T]](y: T*): T = y goo(new B) }
Best regards,
Alexander Podkhalyuzin.
Thu, 2011-12-15, 20:11
#2
Re: Existential type understanding
You could make A covariant in T.
object Problem {
class A[+T]
class B extends A[B]
def goo[T <: A[T]](y: T): T = y
type Y = T forSome {type T <: A[T]}
val x: Y = null
goo(x)
goo[Y](x)
}
It compiles but I don't know why and what it means.
On 15 dec, 13:40, Alexander Podkhalyuzin
wrote:
> Hi guys,
>
> I have problems with understanding of existential types.
>
> object Problem {
> class A[T]
> class Bextends A[B]
> def goo[T<: A[T]](y: T): T = y
> type Y = T forSome {type T <: A[T]}
> val x: Y =null
> goo(x)
> goo[Y](x)
>
> }
>
> In this code goo(x) is compiled, and goo[Y](x) is not. I want to
> understand why. My vision is that it is a bug.
>
> Original problem is trying to understand how to resolve most specific
> alternative in this case:
>
> object Problem {
> class A[T]
> class Bextends A[B]
> def goo[T<: A[T]](y: T): T = y
> def goo[T<: A[T]](y: T*): T = y
>
> goo(new B)
>
> }
>
> Best regards,
> Alexander Podkhalyuzin.
Fri, 2011-12-16, 05:41
#3
Re: Existential type understanding
Yes, I actually discovered, what type inferred for goo(x), it's
something called "T where T <: A[T]", and I see that it is not
existential type. All I can assume is that it's internal compiler type
(skolemized type?), but usually you shouldn't be able to get this type
explicit. And even it's some internal compiler type (or something else)
and it's not a bug, I still can't understand what reason to change
existential type to something different?
Best regards,
Alexander Podkhalyuzin.
15.12.2011 20:54, Daniel Sobral пишет:
> AFAIK, T<: A[T] is not the same type as T forSome { type T<: A[T]
> }. One is existential, the other is not.
>
> On Thu, Dec 15, 2011 at 10:40, Alexander Podkhalyuzin
> wrote:
>> Hi guys,
>>
>> I have problems with understanding of existential types.
>>
>> object Problem {
>> class A[T]
>> class B extends A[B]
>> def goo[T<: A[T]](y: T): T = y
>> type Y = T forSome {type T<: A[T]}
>> val x: Y = null
>> goo(x)
>> goo[Y](x)
>> }
>>
>> In this code goo(x) is compiled, and goo[Y](x) is not. I want to understand
>> why. My vision is that it is a bug.
>>
>> Original problem is trying to understand how to resolve most specific
>> alternative in this case:
>>
>> object Problem {
>> class A[T]
>> class B extends A[B]
>> def goo[T<: A[T]](y: T): T = y
>> def goo[T<: A[T]](y: T*): T = y
>>
>> goo(new B)
>> }
>>
>>
>> Best regards,
>> Alexander Podkhalyuzin.
>
>
AFAIK, T <: A[T] is not the same type as T forSome { type T <: A[T]
}. One is existential, the other is not.
On Thu, Dec 15, 2011 at 10:40, Alexander Podkhalyuzin
wrote:
> Hi guys,
>
> I have problems with understanding of existential types.
>
> object Problem {
> class A[T]
> class B extends A[B]
> def goo[T <: A[T]](y: T): T = y
> type Y = T forSome {type T <: A[T]}
> val x: Y = null
> goo(x)
> goo[Y](x)
> }
>
> In this code goo(x) is compiled, and goo[Y](x) is not. I want to understand
> why. My vision is that it is a bug.
>
> Original problem is trying to understand how to resolve most specific
> alternative in this case:
>
> object Problem {
> class A[T]
> class B extends A[B]
> def goo[T <: A[T]](y: T): T = y
> def goo[T <: A[T]](y: T*): T = y
>
> goo(new B)
> }
>
>
> Best regards,
> Alexander Podkhalyuzin.