diff options
author | Vojin Jovanovic <vojin.jovanovic@epfl.ch> | 2012-01-25 15:24:18 +0100 |
---|---|---|
committer | Vojin Jovanovic <vojin.jovanovic@epfl.ch> | 2012-01-25 15:24:18 +0100 |
commit | f814d40ea917592f78d2e8ca4c78f34ce4b5f297 (patch) | |
tree | cafac6a0d757419132fd75ab788f8163a619780b /test/files/specialized | |
parent | 85daadef89a9ed5c3901a5822221366ee6746d49 (diff) | |
parent | de2b0c68785afc0f801fbe8d2750366e90c9fa70 (diff) | |
download | scala-f814d40ea917592f78d2e8ca4c78f34ce4b5f297.tar.gz scala-f814d40ea917592f78d2e8ca4c78f34ce4b5f297.tar.bz2 scala-f814d40ea917592f78d2e8ca4c78f34ce4b5f297.zip |
Merge branch 'master' into execution-context
Diffstat (limited to 'test/files/specialized')
-rw-r--r-- | test/files/specialized/spec-hlists.check | 2 | ||||
-rw-r--r-- | test/files/specialized/spec-hlists.scala | 29 |
2 files changed, 31 insertions, 0 deletions
diff --git a/test/files/specialized/spec-hlists.check b/test/files/specialized/spec-hlists.check new file mode 100644 index 0000000000..0ab3339bbc --- /dev/null +++ b/test/files/specialized/spec-hlists.check @@ -0,0 +1,2 @@ +class HCons$mcI$sp +class HCons$mcI$sp diff --git a/test/files/specialized/spec-hlists.scala b/test/files/specialized/spec-hlists.scala new file mode 100644 index 0000000000..8c4ac8f610 --- /dev/null +++ b/test/files/specialized/spec-hlists.scala @@ -0,0 +1,29 @@ +/** Test contributed by Stefan Zeiger showing that HLists can be + * specialized. + */ + +sealed trait HList { + type Self <: HList + + type |: [E] = HCons[E, Self] + + final def |: [@specialized E](elem: E): |: [E] = new HCons[E, Self](elem, this.asInstanceOf[Self]) + + def m[@specialized E, T <: AnyRef](x: E): T = null.asInstanceOf[T] +} + +final class HCons[@specialized H, T <: HList](val head: H, val tail: T) extends HList { + type Self = HCons[H, T] +} + +final object HNil extends HList { + type Self = HNil.type +} + +object Test extends App { + val l1 = new HCons(42, "foo" |: HNil) + println(l1.getClass) + + val l2 = 42 |: "abc" |: HNil + println(l2.getClass) +} |