scala - F-bounded existential quantification -
i came across existential quantification f-bounded types while trying understand scala's type system.
let a type
trait a[f <: a[f]] { self: f => } where f f-bounded self-type of a.
and b subtype of a
case class b() extends a[b] if try declare list of a existential quantification
val a: list[t] forsome { type t <: a[t] } i error when assigning a list of b. reason scala infers type list[a[nothing]].
val a: list[t] forsome { type t <: a[t] } = list(b()) // type mismatch when applying simplification rule 4 (as described in scala-spec) covariant occurrence of t may replaced upper bound (here: a[t])
val b: list[a[t]] forsome { type t <: a[t] } = list(b()) both examples should equivalent (if have not misunderstood something), simplified 1 works fine. furthermore following correct , should equivalent:
val c: list[t forsome { type t <: a[t] }] = list(b()) but reason type of c , type of b not equal.
so question is: bug of scala compiler or did misunderstand crucial?
edit: assumption correct, types of c , b not equal, because existential quantification in c not see covariant occurrence of t?
Comments
Post a Comment