Created
December 16, 2012 00:43
-
-
Save rnix/4301540 to your computer and use it in GitHub Desktop.
StackOverflow Question
http://stackoverflow.com/questions/13897885/how-can-i-remove-this-extra-type-parameter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test | |
class X[+T: Numeric](val x: T) | |
abstract class M[T: Numeric] { | |
def apply(x: Int): X[T] | |
final def row = (1 to 10).map(this(_)) | |
} | |
class Y(x: Double, val y: Double) extends X[Double](x) | |
class Z extends M[Double] { | |
def apply(x: Int) = new Y(0.0, 0.0) | |
} | |
object testapp { | |
def main(args: Array[String]): Unit = | |
(new Z).row.map(r=>println(r.y)) // <- y is not a member of X[Double]. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test | |
class X[+T: Numeric](val x: T) | |
abstract class M[N: Numeric, T <: X[N]] { | |
def apply[A <: T](x: Int): X[A] | |
final def row = (1 to 10).map(this(_)) | |
} | |
class Y(x: Double, val y: Double) extends X[Double](x) | |
class Z extends M[Double, Y] { // <- Z must be abstract because it doesn't implement apply. | |
def apply(x: Int) = new Y(0.0, 0.0) | |
} | |
object testapp { | |
def main(args: Array[String]): Unit = | |
(new Z).row.map(r => println(r.y)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Like test2.scala, I can't implement apply properly. | |
package test | |
class X[+T: Numeric](val x: T) | |
abstract class M[T: Numeric] { | |
def apply[A <: X[T]](x: Int): A | |
final def row = (1 to 10).map(this(_)) | |
} | |
class Y(x: Double, val y: Double) extends X[Double](x) | |
class Z extends M[Double] { // <- Z must be abstract because it doesn't implement apply. | |
def apply[A <: X[Double]](x: Int) = new Y(0.0, 0.0) | |
} | |
object testapp { | |
def main(args: Array[String]): Unit = | |
(new Z).row.map(r => println(r.y)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test | |
class X[+T: Numeric](val x: T) | |
abstract class M[A: Numeric, B <: X[A]] { // <- I really don't like having to specify two type parameters. | |
def apply(x: Int): B | |
final def row = (1 to 10).map(this(_)) | |
} | |
class Y(x: Double, val y: Double) extends X[Double](x) | |
class Z extends M[Double, Y] { | |
def apply(x: Int) = new Y(0.0, 0.0) | |
} | |
object testapp { | |
def main(args: Array[String]): Unit = { | |
(new Z).row.map(r => println(r.y)) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test | |
class X[T: Numeric](val x: T) | |
abstract class M[T <: X[T]] { | |
def apply(x: Int): T | |
final def row = (1 to 10).map(this(_)) | |
} | |
class Y(x: Double, val y: Double) extends X[Double](x) | |
class Z extends M[Y] { // <- Y doesn't conform to T <: X[T]. Why? | |
def apply(x: Int) = new Y(0.0, 0.0) | |
} | |
object testapp { | |
def main(args: Array[String]): Unit = { | |
(new Z).row.map(r => println(r.y)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment