Skip to content

Instantly share code, notes, and snippets.

@rnix
Created December 16, 2012 00:43
Show Gist options
  • Save rnix/4301540 to your computer and use it in GitHub Desktop.
Save rnix/4301540 to your computer and use it in GitHub Desktop.
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].
}
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))
}
// 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))
}
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))
}
}
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