bounded-quantification

F-bounded quantification through type member instead of type parameter?

陌路散爱 提交于 2019-12-29 08:55:08
问题 I would like to move a type parameter to a type member. This is the starting point which works: trait Sys[S <: Sys[S]] { type Tx type Id <: Identifier[S#Tx] } trait Identifier[Tx] { def dispose()(implicit tx: Tx): Unit } trait Test[S <: Sys[S]] { def id: S#Id def dispose()(implicit tx: S#Tx) { id.dispose() } } What annoys me is that I'm carrying around a type parameter [S <: Sys[S]] throughout my entire libraries. So what I was thinking is this: trait Sys { type S = this.type // ? type Tx

Understanding “type arguments do not conform to type parameter bounds” errors in Scala

为君一笑 提交于 2019-12-23 09:18:05
问题 Why don't the following work? scala> abstract class Foo[B<:Foo[B]] defined class Foo scala> class Goo[B<:Foo[B]](x: B) defined class Goo scala> trait Hoo[B<:Foo[B]] { self: B => new Goo(self) } <console>:9: error: inferred type arguments [Hoo[B] with B] do not conform to class Goo's type parameter bounds [B <: Foo[B]] trait Hoo[B<:Foo[B]] { self: B => new Goo(self) } ^ scala> trait Hoo[B<:Foo[B]] extends Foo[B] { new Goo(this) } <console>:9: error: inferred type arguments [Hoo[B]] do not

Scala converting recursively bounded type parameter (F-bounded) to type member

风格不统一 提交于 2019-12-03 08:24:16
问题 How would I convert: trait Foo[A <: Foo[A]] to a type member? I.e., I want something along the lines of the following: trait Foo { type A <: Foo {type A = ???} } but I am having difficulty because the name A is already taken within the type refinement. This question is similar (and spawned from): F-bounded quantification through type member instead of type parameter? 回答1: Use a self-type: scala> trait Foo { self => type A <: Foo {type A = self.A}} defined trait Foo scala> class Bar extends