diff options
author | Vojin Jovanovic <vojin.jovanovic@epfl.ch> | 2012-01-09 18:11:10 +0100 |
---|---|---|
committer | Vojin Jovanovic <vojin.jovanovic@epfl.ch> | 2012-01-09 18:11:10 +0100 |
commit | 1126912bce5d098571c1bd29a04e4781e19c3d85 (patch) | |
tree | 79e753014c1adfa26e39e32911125bfc0ad8ee4c /test/files/run/type-currying.scala | |
parent | 5a4b555c378d79d57b59dfd6edafd2b9a59866bb (diff) | |
parent | 820491ed6376e9f8f8a8102387495113dce55444 (diff) | |
download | scala-1126912bce5d098571c1bd29a04e4781e19c3d85.tar.gz scala-1126912bce5d098571c1bd29a04e4781e19c3d85.tar.bz2 scala-1126912bce5d098571c1bd29a04e4781e19c3d85.zip |
Merge branch 'master' into execution-context
Diffstat (limited to 'test/files/run/type-currying.scala')
-rw-r--r-- | test/files/run/type-currying.scala | 58 |
1 files changed, 58 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..f9764c64f0 --- /dev/null +++ b/test/files/run/type-currying.scala @@ -0,0 +1,58 @@ +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) + } +} + +class A { + object Foo { + def apply[T] = Bar + } + object Bar { + def apply() = Foo + } + + def f() = Foo + def g = f()[Int]()[String]() + def h = Foo[Foo.type]()[Foo.type]() +} |