diff options
author | Martin Odersky <odersky@gmail.com> | 2004-04-23 14:11:16 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2004-04-23 14:11:16 +0000 |
commit | 92fcc53be94a107f3b560b855564bc39ba8f2372 (patch) | |
tree | c1b8e40ef4d21e18741b9f286d6e9047d39cc44e /test/files/pos/viewtest3.scala | |
parent | abe707d00a280e8f33cbc2a064cb970460c19d7d (diff) | |
download | scala-92fcc53be94a107f3b560b855564bc39ba8f2372.tar.gz scala-92fcc53be94a107f3b560b855564bc39ba8f2372.tar.bz2 scala-92fcc53be94a107f3b560b855564bc39ba8f2372.zip |
*** empty log message ***
Diffstat (limited to 'test/files/pos/viewtest3.scala')
-rw-r--r-- | test/files/pos/viewtest3.scala | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test/files/pos/viewtest3.scala b/test/files/pos/viewtest3.scala new file mode 100644 index 0000000000..dfed0dbf52 --- /dev/null +++ b/test/files/pos/viewtest3.scala @@ -0,0 +1,59 @@ +package testview; + +trait Tree[+a <% Ordered[a]] { + def insert[b >: a <% Ordered[b]](x: b): Tree[b]; + def elements: List[a] +} + +object Empty extends Tree[All] { + def insert[b >: All <% Ordered[b]](x: b): Tree[b] = new Node(x, Empty, Empty); + def elements: List[All] = List(); +} + +class Node[+a <% Ordered[a]](elem: a, l: Tree[a], r: Tree[a]) extends Tree[a] { + def insert[b >: a <% Ordered[b]](x: b): Tree[b] = + if (x == elem) this + else if (x < elem) new Node(elem, l insert x, r) + else new Node(elem, l, r insert x); + def elements: List[a] = + l.elements ::: List(elem) ::: r.elements +} + +case class Str(elem: String) extends Ordered[Str] { + def compareTo[b >: Str <% Ordered[b]](that: b): int = that match { + case that1: Str => this.elem compareTo that1.elem + case _ => -(that compareTo this) + } +} + +object Test { +// import O.view; + + private def toCharList(s: String): List[Char] = + if (s.length() == 0) List() + else s.charAt(0) :: toCharList(s.substring(1)); + + def main(args: Array[String]) = { + { + var t: Tree[String] = Empty; + for (val s <- args) { + t = t insert s + } + System.out.println(t.elements) + } + { + var t: Tree[Str] = Empty; + for (val s <- args) { + t = t insert Str(s) + } + System.out.println(t.elements) + } + { + var t: Tree[List[char]] = Empty; + for (val s <- args) { + t = t insert toCharList(s) + } + System.out.println(t.elements) + } + } +} |