In Scala 2.10, given class Foo[F[_]] , I cannot write
scala> x.isInstanceOf[Foo[_]] <console>:10: error: _$1 takes no type parameters, expected: one x.isInstanceOf[Foo[_]] ^
or
scala> x.isInstanceOf[Foo[_[_]]] <console>:11: error: _$1 does not take type parameters x.isInstanceOf[Foo[_[_]]] ^
I can write x.isInstanceOf[Foo[F] forSome { type F[_]] } which gives an unchecked warning. I tried to post the @unchecked annotation in different places, but none of them work:
scala> x.isInstanceOf[Foo[H] @unchecked forSome {type H[_]}] <console>:11: warning: abstract type H in type Foo[H] @unchecked forSome { type H[_] <: Any } is unchecked since it is eliminated by erasure x.isInstanceOf[Foo[H] @unchecked forSome {type H[_]}] ^ scala> x.isInstanceOf[Foo[H @unchecked] forSome {type H[_]}] <console>:11: warning: abstract type H in type Foo[H @unchecked] is unchecked since it is eliminated by erasure x.isInstanceOf[Foo[H @unchecked] forSome {type H[_]}] ^ <console>:11: error: kinds of the type arguments (? @unchecked) do not conform to the expected kinds of the type parameters (type F) in class Foo. ? @unchecked type parameters do not match type F expected parameters: <none> has no type parameters, but type F has one x.isInstanceOf[Foo[H @unchecked] forSome {type H[_]}] ^ scala> x.isInstanceOf[Foo[H] forSome {type H[_] @unchecked}] <console>:1: error: `=', `>:', or `<:' expected x.isInstanceOf[Foo[H] forSome {type H[_] @unchecked}] ^
Is there a way to write this existential type without warning?
source share