Why are the bounds of type parameters ignored when using existential types in Scala? -
what mean this:
scala> class bounded[t <: string](val t: t) defined class bounded scala> val b: bounded[_] = new bounded("some string") b: bounded[_] = bounded@2b0a141e scala> b.t res0: = string
why res0 have type , not string? sure know b.t @ least string. writing
val b: bounded[_ <: string] = new bounded("some string")
works, redundant respect declaration of class itself.
first, have edited question title. not using dependent types, scala doesn't have anyway, existential types. second, not inferring anything, explicitly declaring type.
now, if did write bounded[any]
, scala wouldn't let you. however, 1 of uses of existential types deal situations type parameter unknown -- such java raw types, where.
so guess making exception in situation seems obvious enough break other situation existential type way deal something.
Comments
Post a Comment