scala - Getting F-bounded polymorphism to work on a base trait with type parameters? -


trait a[t, this[_] <: a[t, this]] case class b[t]() extends a[t, b]  <console>:8: error: type arguments [t,b] not conform trait a's type parameter bounds [t,this[_] <: a[t,this]]        case class b[t]() extends a[t, b] 

this seems odd me, because seems should work? guidance welcome...

thank you

it seems may have misplaced constraint on second parameter:

trait a[t, this[_ <: a[t, this]]] case class b[t]() extends a[t, b] 

you try:

trait a[t, u <: a[t, u]] case class b[t]() extends a[t, b[t]]  

if want mixin multiple such traits, unfortunately can't use generics (you can't extend same trait twice different generic parameter). can, however, use abstract type member express f-bound, , mixin multiple such traits:

trait step { self =>     type self <: step { type self <: self.self }     val name: string     def next: self }  trait foolike extends step {      val foomarker = "foo" } case class foo(name: string) extends foolike {     type self = foo     def next = foo(name + "i") }  trait barlike extends step {     val barmarker = "bar" }  case class foobarlike(name: string) extends barlike foolike {     override type self = foobarlike     override def next = this.copy(name + "j") } 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -