- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
manifest density
Fri, 2009-07-17, 02:34
[Hmm, this bounced to "scala-internals@epfl.ch" but as it's an alias I'm
confident that's the address I've always used for internals. Resending:]
An interesting side effect of some fixes I checked in today is that in
trunk Manifest's <:< is a lot less... wrong. (The code that busted it
was introduced somewhere since 2.7, so it looks like 2.7.5 does the
right thing.) But for anyone out there who might have been scratching
their head for reasons unrelated to hygiene, here is a test program:
import scala.reflect.Manifest.classType
val iM = classType(classOf[Int])
val sM = classType(classOf[String])
val oM = classType(classOf[AnyRef])
val listInt = classType(classOf[List[_]], iM)
val listString = classType(classOf[List[_]], sM)
val listAnyRef = classType(classOf[List[_]], oM)
val lists = List(
"List[Int]" -> listInt,
"List[String]" -> listString,
"List[AnyRef]" -> listAnyRef
)
for (x1 <- lists ; x2 <- lists)
println("%s <:< %s = %s".format(x1._1, x2._1, (x1._2 <:< x2._2)))
Here is what this outputs as of today:
List[Int] <:< List[Int] = true
List[Int] <:< List[String] = false
List[Int] <:< List[AnyRef] = false
List[String] <:< List[Int] = false
List[String] <:< List[String] = true
List[String] <:< List[AnyRef] = true
List[AnyRef] <:< List[Int] = false
List[AnyRef] <:< List[String] = false
List[AnyRef] <:< List[AnyRef] = true
Pretty smart, Mr. Manifest! Until today, not so much:
List[Int] <:< List[Int] = true
List[Int] <:< List[String] = true
List[Int] <:< List[AnyRef] = true
List[String] <:< List[Int] = true
List[String] <:< List[String] = true
List[String] <:< List[AnyRef] = true
List[AnyRef] <:< List[Int] = true
List[AnyRef] <:< List[String] = true
List[AnyRef] <:< List[AnyRef] = true
Oh Mr. Manifest, you'll believe ANYTHING!