diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2009-10-22 17:04:20 +0000 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2009-10-22 17:04:20 +0000 |
commit | bf584e53207b837a3103a59614177ba39f06015e (patch) | |
tree | e68eeb41c745ccc848c5fbcd505249880daf021f /test/files/pos/tcpoly_infer_ticket1864.scala | |
parent | a2eab2215a7671e8abd8189ccc59388dffc1f3de (diff) | |
download | scala-bf584e53207b837a3103a59614177ba39f06015e.tar.gz scala-bf584e53207b837a3103a59614177ba39f06015e.tar.bz2 scala-bf584e53207b837a3103a59614177ba39f06015e.zip |
the essence of tcpoly inference + test cases
fixes to check files and removed nonapplicable test case Tuple2 impl,
but commented out so that we can bootstrap whitespace...
Diffstat (limited to 'test/files/pos/tcpoly_infer_ticket1864.scala')
-rw-r--r-- | test/files/pos/tcpoly_infer_ticket1864.scala | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/test/files/pos/tcpoly_infer_ticket1864.scala b/test/files/pos/tcpoly_infer_ticket1864.scala new file mode 100644 index 0000000000..587483287d --- /dev/null +++ b/test/files/pos/tcpoly_infer_ticket1864.scala @@ -0,0 +1,51 @@ +import scala.collection.mutable.{Buffer, ArrayBuffer} + +class RichBuffer[T, B[U] <: Buffer[U]](buffer: Buffer[T]) { + def mymap[S](f: T => S)(implicit rv: B[S]): B[S] = { + buffer.foreach{ e => + rv += f(e) + } + rv + } +} + +object Application { + def mymap2[T, B[U] <: Buffer[U], S](buffer: B[T], f: T => S)(implicit rv: B[S]): B[S] = { + buffer.foreach{ e => + rv += f(e) + } + rv + } + + def mymap3[T, B <: Buffer[T], S](buffer: B, f: T => T)(implicit rv: B): B = { + buffer.foreach{ e => + rv += f(e) + } + rv + } + + def mymap4[T, B[U] <: Buffer[U], S](buffer: B[T])(f: T => S) (implicit rv: B[S]): B[S] = { + buffer.foreach{ e => + rv += f(e) + } + rv + } + + + def main(args: Array[String]) { + implicit def richBuffer[T, B[U] <: Buffer[U]](buffer: B[T]): RichBuffer[T, B] = + new RichBuffer[T, B](buffer) + + implicit val rv = new ArrayBuffer[Int] + val buf = new ArrayBuffer[Int] + (1 to 5).foreach(buf += _) + buf.mymap(x => x*x) + richBuffer(buf).mymap[Int](x => x*x) + richBuffer[Int, ArrayBuffer](buf).mymap[Int](x => x*x) + mymap2(buf, (x: Int) => x*x) + mymap2[Int, ArrayBuffer, Int](buf, (x: Int) => x*x) + // mymap3(buf, x => x*x) // compiler error + mymap3(buf, (x: Int) => x*x) + mymap4(buf)(x => x*x) + } +} |