summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-01-17 10:05:15 -0800
committerPaul Phillips <paulp@improving.org>2012-01-17 10:05:15 -0800
commitcc9871f8dd4f685660976f1a6e5e07c28a4c53a7 (patch)
tree56d4ed9067cb502083fa4017952b323cfd3bb897 /test
parent9d55bf45cd13107ad8f3e5e75737f37e75b22f90 (diff)
parent1591c14e504246d2cb49b1f7f3e00f6d986f6a06 (diff)
downloadscala-cc9871f8dd4f685660976f1a6e5e07c28a4c53a7.tar.gz
scala-cc9871f8dd4f685660976f1a6e5e07c28a4c53a7.tar.bz2
scala-cc9871f8dd4f685660976f1a6e5e07c28a4c53a7.zip
Merge branch 'specialized/hlist' of https://github.com/dragos/scala into develop
Diffstat (limited to 'test')
-rw-r--r--test/files/specialized/spec-hlists.check2
-rw-r--r--test/files/specialized/spec-hlists.scala29
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)
+}