summaryrefslogtreecommitdiff
path: root/test/files/pos/viewtest2.scala
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2006-10-10 16:00:00 +0000
committermichelou <michelou@epfl.ch>2006-10-10 16:00:00 +0000
commit2f0f432ebcbbdf6fb25c8f500ee2fffe6b8ed025 (patch)
tree401e18f07778ba1bb58d66eff6b91ede4146ab71 /test/files/pos/viewtest2.scala
parentdcbcc2938384bd08794e6776c17e8c33b69672a7 (diff)
downloadscala-2f0f432ebcbbdf6fb25c8f500ee2fffe6b8ed025.tar.gz
scala-2f0f432ebcbbdf6fb25c8f500ee2fffe6b8ed025.tar.bz2
scala-2f0f432ebcbbdf6fb25c8f500ee2fffe6b8ed025.zip
updated docs/examples/*.scala
Diffstat (limited to 'test/files/pos/viewtest2.scala')
-rw-r--r--test/files/pos/viewtest2.scala60
1 files changed, 30 insertions, 30 deletions
diff --git a/test/files/pos/viewtest2.scala b/test/files/pos/viewtest2.scala
index 51df563633..70257baa29 100644
--- a/test/files/pos/viewtest2.scala
+++ b/test/files/pos/viewtest2.scala
@@ -1,4 +1,4 @@
-package test;
+package test
/** A trait for totally ordered data.
*/
@@ -10,15 +10,15 @@ trait Ordered[+a] {
* x == 0 iff this == that
* x > 0 iff this > that
*/
- def compareTo [b >: a <% Ordered[b]](that: b): int;
+ def compareTo [b >: a <% Ordered[b]](that: b): int
- def < [b >: a <% Ordered[b]](that: b): boolean = (this compareTo that) < 0;
+ def < [b >: a <% Ordered[b]](that: b): boolean = (this compareTo that) < 0
- def > [b >: a <% Ordered[b]](that: b): boolean = (this compareTo that) > 0;
+ def > [b >: a <% Ordered[b]](that: b): boolean = (this compareTo that) > 0
- def <= [b >: a <% Ordered[b]](that: b): boolean = (this compareTo that) <= 0;
+ def <= [b >: a <% Ordered[b]](that: b): boolean = (this compareTo that) <= 0
- def >= [b >: a <% Ordered[b]](that: b): boolean = (this compareTo that) >= 0;
+ def >= [b >: a <% Ordered[b]](that: b): boolean = (this compareTo that) >= 0
}
@@ -26,13 +26,13 @@ object O {
implicit def view1(x: String): Ordered[String] = new Ordered[String] {
def compareTo [b >: String <% Ordered[b]](y: b): int = y match {
- case y1: String => x compareTo y1;
+ case y1: String => x compareTo y1
case _ => -(y compareTo x)
}
}
implicit def view2(x: char): Ordered[char] = new Ordered[char] {
def compareTo [b >: char <% Ordered[b]](y: b): int = y match {
- case y1: char => x - y1;
+ case y1: char => x - y1
case _ => -(y compareTo x)
}
}
@@ -40,37 +40,37 @@ object O {
implicit def view3[a <% Ordered[a]](x: List[a]): Ordered[List[a]] =
new Ordered[List[a]] {
def compareTo [b >: List[a] <% Ordered[b]](y: b): int = y match {
- case y1: List[a] => compareLists(x, y1);
- case _ => -(y compareTo x)
+ case y1: List[a] => compareLists(x, y1)
+ case _ => -(y compareTo x)
}
private def compareLists(xs: List[a], ys: List[a]): int = {
- if (xs.isEmpty && ys.isEmpty) 0
- else if (xs.isEmpty) -1
- else if (ys.isEmpty) 1
- else {
- val s = xs.head compareTo ys.head;
- if (s != 0) s
- else compareLists(xs.tail, ys.tail)
- }
+ if (xs.isEmpty && ys.isEmpty) 0
+ else if (xs.isEmpty) -1
+ else if (ys.isEmpty) 1
+ else {
+ val s = xs.head compareTo ys.head;
+ if (s != 0) s
+ else compareLists(xs.tail, ys.tail)
+ }
}
}
}
trait Tree[+a <% Ordered[a]] {
- def insert[b >: a <% Ordered[b]](x: b): Tree[b];
+ 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();
+ 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);
+ else new Node(elem, l, r insert x)
def elements: List[a] =
l.elements ::: List(elem) ::: r.elements
}
@@ -83,31 +83,31 @@ case class Str(elem: String) extends Ordered[Str] {
}
object Test {
- import O._;
+ import O._
private def toCharList(s: String): List[Char] =
if (s.length() == 0) List()
- else s.charAt(0) :: toCharList(s.substring(1));
+ else s.charAt(0) :: toCharList(s.substring(1))
def main(args: Array[String]) = {
{
- var t: Tree[String] = Empty;
+ var t: Tree[String] = Empty
for (val s <- args) {
- t = t insert s
+ t = t insert s
}
System.out.println(t.elements)
}
{
- var t: Tree[Str] = Empty;
+ var t: Tree[Str] = Empty
for (val s <- args) {
- t = t insert Str(s)
+ t = t insert Str(s)
}
System.out.println(t.elements)
}
{
- var t: Tree[List[char]] = Empty;
+ var t: Tree[List[char]] = Empty
for (val s <- args) {
- t = t insert toCharList(s)
+ t = t insert toCharList(s)
}
System.out.println(t.elements)
}