From ee273f5e7373fa54dc6e81f4488519635344e2e3 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 19 Feb 2003 14:49:03 +0000 Subject: *** empty log message *** --- test/files/pos/List1.scala | 14 ++--- test/files/pos/List2.scala | 139 --------------------------------------------- 2 files changed, 7 insertions(+), 146 deletions(-) delete mode 100644 test/files/pos/List2.scala (limited to 'test/files') diff --git a/test/files/pos/List1.scala b/test/files/pos/List1.scala index 60c23634bf..a52c95b1c8 100644 --- a/test/files/pos/List1.scala +++ b/test/files/pos/List1.scala @@ -4,13 +4,13 @@ module lists { def isEmpty: Boolean; def head: a; def tail: List[a]; - def prepend(x: a) = Cons@[a](x, this); + def prepend(x: a) = Cons[a](x, this); } def Nil[a] = new List[a] { def isEmpty = True; - def head = error@[a]("head of Nil"); - def tail = error@[List[a]]("tail of Nil"); + def head = error[a]("head of Nil"); + def tail = error[List[a]]("tail of Nil"); } def Cons[a](x: a, xs: List[a]): List[a] = new List[a] { @@ -20,10 +20,10 @@ module lists { } def foo = { - val intnil = Nil@[Int]; + val intnil = Nil[Int]; val intlist = intnil.prepend(1).prepend(1+1); val x: Int = intlist.head; - val strnil = Nil@[String]; + val strnil = Nil[String]; val strlist = strnil.prepend("A").prepend("AA"); val y: String = strlist.head; () @@ -32,9 +32,9 @@ module lists { class IntList() extends List[Int] { def isEmpty: Boolean = False; def head: Int = 1; - def foo: List[Int] with { def isEmpty: True.type; def head: Int; def tail: List[Int] } = Nil@[Int]; + def foo: List[Int] with { def isEmpty: True.type; def head: Int; def tail: List[Int] } = Nil[Int]; def tail0: List[Int] = foo.prepend(1).prepend(1+1); - def tail: List[Int] = Nil@[Int].prepend(1).prepend(1+1); + def tail: List[Int] = Nil[Int].prepend(1).prepend(1+1); } def foo2 = { diff --git a/test/files/pos/List2.scala b/test/files/pos/List2.scala deleted file mode 100644 index 3d4087e538..0000000000 --- a/test/files/pos/List2.scala +++ /dev/null @@ -1,139 +0,0 @@ -abstract final class List[a] with { - def ::(x: a): List[a] = cons(x, this); - - def head: a = match { - case [] => error("[].head"); - case x :: xs => x - } - - def tail: List[a] = match { - case [] => error("[].tail"); - case x :: xs => xs - } - - def isEmpty = match { - case [] => False; - case _ :: _ => True; - } - - def length: Int = match { - case [] => 0; - case x :: xs => 1 + xs.length; - } - - def ::: (that: List[a]): List[a] = match { - case [] => that; - case x :: xs => x :: xs ::: that - } - - def append(x: a): List[a] = this ::: x :: []; - - def map[b](f: (a)b): List[b] = match { - case [] => []; - case x :: xs => f(x) :: (xs map f) - } - - def flatMap[b](f: (a)List[b]): List[b] = match { - case [] => []; - case x :: xs => f(x) ::: (xs flatMap f) - } - - def filter(p: (a)Boolean): List[a] = match { - case [] => []; - case x :: xs => if (p(x)) x :: (xs filter p) else xs filter p - } - - def foldl[b](f: (b, a)b)(z: b): b = match { - case [] => z; - case x :: xs => (xs foldl f)(f(z, head)) - } - - def foldr[b](f: (a, b)b)(z: b): b = match { - case [] => z; - case x :: xs => f(x, (xs foldr f)(z)) - } - - def foldl1(f: (a, a)a): a = match { - case [] => error("[].foldl1"); - case x :: xs => (xs foldl f)(x) - } - - def foldr1(f: (a, a)a): a = match { - case [] => error("[].foldr1"); - case x :: [] => x; - case x :: xs => f(x, (xs foldr1 f)) - } - - def forall(p: (a)Boolean): Boolean = match { - case [] => True; - case x :: xs => p(x) && (xs forall p) - } - - def exists(p: (a)Boolean): Boolean = match { - case [] => False; - case x :: xs => p(x) || (xs exists p) - } - - def take(n: Int): List[a] = match { - case [] => []; - case x :: xs => if (n == 0) [] else x :: (xs take (n - 1)) - } - - def drop(n: Int): List[a] = match { - case [] => []; - case x :: xs => if (n == 0) this else xs drop (n - 1) - } - - def takeWhile(p: (a)Boolean): List[a] = match { - case [] => []; - case x :: xs => if (p(x)) x :: (xs takeWhile p) else [] - } - - def dropWhile(p: (a)Boolean): List[a] = match { - case [] => []; - case x :: xs => if (p(x)) (xs dropWhile p) else this - } - - def init: List[a] = match { - case [] => error("[].init"); - case x :: [] => []; - case x :: xs => xs.init - } - - def last: a = match { - case [] => error("[].last"); - case x :: [] => x; - case x :: xs => xs.last - } - - def reverse: List[a] = { - def snoc(xs: List[a], x: a) = x :: xs; - foldl(snoc)([]) - } - - def zip[b](that: List[b]): List[(a,b)] = (this, that) match { - case (x :: xs, y :: ys) => (x, y) :: (xs zip ys) - case _ => [] - } - - override def toString(): String = "[" + mkString(",") + "]"; - def mkString(sep: String): String = match { - case [] => ""; - case x :: [] => x.toString(); - case x :: xs => x.toString() + sep + xs.toString() - } -} - -def error[a](x: String):a = (new java.lang.RuntimeException(x)).throw; - -case class Nil[b] extends List[b]; -case class ::_class[b](x: b)(xs: List[b]) extends List[b]; -def cons[a](x: a, xs: List[a]) = ::_class(x)(xs); -def nil[a] = new Nil[a]; - - - - - - - -- cgit v1.2.3