summaryrefslogtreecommitdiff
path: root/test/files/run/type-currying.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-12-27 07:00:07 -0800
committerPaul Phillips <paulp@improving.org>2011-12-27 07:06:04 -0800
commit935ba9ba3021b518dab8f22c1e5d897865777aab (patch)
tree444c2f7c375b91beb128e3f47f42f3d12934dbfc /test/files/run/type-currying.scala
parentf737e35ddf43599043ab78404c4f9a13e6d02c9b (diff)
downloadscala-935ba9ba3021b518dab8f22c1e5d897865777aab.tar.gz
scala-935ba9ba3021b518dab8f22c1e5d897865777aab.tar.bz2
scala-935ba9ba3021b518dab8f22c1e5d897865777aab.zip
Consecutive type application.
The parser through I think a quirk of history would not allow back to back type applications, like expr[T1, T2][T3, T4] Now it does, meaning the only thing it can: val n0 = Partial[immutable.HashMap][String][Int] ++ Seq(("a", 1)) val n1 = Partial.apply[immutable.HashMap].apply[String].apply[Int] ++ Seq(("a", 1)) assert(n0 == n1)
Diffstat (limited to 'test/files/run/type-currying.scala')
-rw-r--r--test/files/run/type-currying.scala45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/files/run/type-currying.scala b/test/files/run/type-currying.scala
new file mode 100644
index 0000000000..717e0763a3
--- /dev/null
+++ b/test/files/run/type-currying.scala
@@ -0,0 +1,45 @@
+import scala.collection.{ mutable, immutable, generic }
+import generic.CanBuildFrom
+
+object Partial {
+ type KnownContainer[CC[K, V] <: collection.Map[K, V]] = {
+ def values[V] : KnownValues[CC, V]
+ def apply[K] : KnownKeys[CC, K]
+ }
+ type KnownKeys[CC[K, V] <: collection.Map[K, V], K] = {
+ def apply[V](implicit cbf: CanBuildFrom[_, (K, V), CC[K, V]]): CC[K, V]
+ }
+ type KnownValues[CC[K, V] <: collection.Map[K, V], V] = {
+ def apply[K](implicit cbf: CanBuildFrom[_, (K, V), CC[K, V]]): CC[K, V]
+ }
+
+ def apply[CC[K, V] <: collection.Map[K, V]] : KnownContainer[CC] = new {
+ def values[V] : KnownValues[CC, V] = new {
+ def apply[K](implicit cbf: CanBuildFrom[_, (K, V), CC[K, V]]) = cbf().result
+ }
+ def apply[K] = new {
+ def apply[V](implicit cbf: CanBuildFrom[_, (K, V), CC[K, V]]) = cbf().result
+ }
+ }
+}
+
+object Test {
+ val m = Partial[immutable.TreeMap]
+ val m1 = m[String]
+ val m2 = m[Int][Int]
+
+ val mutableBippy = Partial[mutable.HashMap][String][Int]
+ mutableBippy("abc") = 55
+
+ val immutableBippy = Partial[immutable.HashMap].values[Int]
+ def make[T](xs: T*) = immutableBippy[T] ++ xs.zipWithIndex
+
+ val n0 = Partial[immutable.HashMap][String][Int] ++ Seq(("a", 1))
+ val n1 = Partial.apply[immutable.HashMap].apply[String].apply[Int] ++ Seq(("a", 1))
+
+ def main(args: Array[String]): Unit = {
+ println(mutableBippy)
+ make('a' to 'z': _*).toList.sorted foreach println
+ assert(n0 == n1)
+ }
+}