diff options
author | Martin Odersky <odersky@gmail.com> | 2006-07-24 14:22:00 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2006-07-24 14:22:00 +0000 |
commit | 5bdedbd45315a010ad852b5f2b12715a824fee26 (patch) | |
tree | fd075aaa156ca6951799fac224fba231b45197c8 | |
parent | 343c15fe833dc763750f8ed3ba65e9458da09d05 (diff) | |
download | scala-5bdedbd45315a010ad852b5f2b12715a824fee26.tar.gz scala-5bdedbd45315a010ad852b5f2b12715a824fee26.tar.bz2 scala-5bdedbd45315a010ad852b5f2b12715a824fee26.zip |
21 files changed, 159 insertions, 190 deletions
diff --git a/src/actors/scala/Reactions.scala b/src/actors/scala/Reactions.scala new file mode 100755 index 0000000000..041cc793bd --- /dev/null +++ b/src/actors/scala/Reactions.scala @@ -0,0 +1,54 @@ +package scala + +/** An enclosing trait for reactions. + * Examples of reactions are: actor.receive's, event.handle's, etc + * @param m The input type of a Reaction; typically the type of messages or events. + */ +trait Reactions[m] { + + /** The partial function underlying a reaction. Note that this is formulated + * in CPS style. + */ + type Re[r] = PartialFunction[m, (r => unit) => unit] + + /** Activate the given partial function `f', for instance by reading + * a message or waiting for an event, and applying `f' to the result. + */ + def activate[r](f: Re[r]): (r => unit) => unit + + /** The class of reactions + * @param r The type of values returned by the reaction. + * (More precisely, the type of values passed to its continuation) + * @param fun The partial function underlying a reaction + */ + class Reaction[+r](private val fun: Re[r]) extends Responder[r] { + + def respond(k: r => unit): unit = activate(fun)(k) + + override def map[s](f: r => s) = new Reaction[s] ( + fun andThen { + result: ((r => unit) => unit) => + k: (s => unit) => result((x: r) => k(f(x))) + } + ) + + def flatMap[s](f: r => Reaction[s]) = new Reaction[s] ( + fun andThen { + result: ((r => unit) => unit) => + k: (s => unit) => result((x: r) => f(x).respond(k)) + } + ) + + override def filter(p: r => boolean) = new Reaction[r] ( + fun andThen { + result: ((r => unit) => unit) => + k: (r => unit) => result((x: r) => if (p(x)) k(x) else ()) + } + ) + + def orElse[r1 >: r](that: Reaction[r1]) = new Reaction[r1] ( + this.fun orElse that.fun + ) + } +} + diff --git a/src/actors/scala/actors/multi/TimerThread.scala b/src/actors/scala/actors/multi/TimerThread.scala index fc1c2162da..436b27354f 100644 --- a/src/actors/scala/actors/multi/TimerThread.scala +++ b/src/actors/scala/actors/multi/TimerThread.scala @@ -25,10 +25,7 @@ case class Signal() object TimerThread extends AnyRef with Runnable { case class WakedActor(actor: MailBox, time: long, reason: String) extends Ordered[WakedActor] { var valid = true - def compare [b >: WakedActor <% Ordered[b]](that: b): int = that match { - case that2: WakedActor => -(this.time compare that2.time) - case _ => error("not comparable") - } + def compare (that: WakedActor): int = -(this.time compare that.time) } var queue = new PriorityQueue[WakedActor] diff --git a/src/compiler/scala/tools/nsc/models/Models.scala b/src/compiler/scala/tools/nsc/models/Models.scala index 11d422c5d4..b503c18586 100644 --- a/src/compiler/scala/tools/nsc/models/Models.scala +++ b/src/compiler/scala/tools/nsc/models/Models.scala @@ -138,12 +138,12 @@ abstract class Models { override def toString() : String = tree.toString(); - def compare [b >: HasTree <% Ordered[b]](that: b): Int = that match { - case ht : HasTree => - val result = tree.symbol.nameString.compare(ht.tree.symbol.nameString); - if (result != 0) result; - else toString().compare(ht.toString()); + def compare (ht: HasTree): Int = { + val result = tree.symbol.nameString.compare(ht.tree.symbol.nameString); + if (result != 0) result; + else toString().compare(ht.toString()) } + def kind = kindOf(tree.symbol); override def add(from : Composite, model : HasTree) : Unit = { parent.add(from, model); } diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala index fb806ea01a..6efa735301 100644 --- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala +++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala @@ -80,6 +80,7 @@ trait Definitions requires SymbolTable { var SerializableClass: Symbol = _ var PredefModule: Symbol = _ def Predef_classOf = getMember(PredefModule, nme.classOf) + def Predef_identity = getMember(PredefModule, nme.identity) var ConsoleModule: Symbol = _ var MatchErrorClass: Symbol = _ var MatchErrorModule: Symbol = _ diff --git a/src/compiler/scala/tools/nsc/symtab/StdNames.scala b/src/compiler/scala/tools/nsc/symtab/StdNames.scala index f83aca263a..1a41659a61 100644 --- a/src/compiler/scala/tools/nsc/symtab/StdNames.scala +++ b/src/compiler/scala/tools/nsc/symtab/StdNames.scala @@ -250,6 +250,7 @@ trait StdNames requires SymbolTable { val hashCode_ = newTermName("hashCode") val hasNext = newTermName("hasNext") val head = newTermName("head") + val identity = newTermName("identity") val isInstanceOf = newTermName("isInstanceOf") val isInstanceOfErased = newTermName("isInstanceOf$erased") val isDefinedAt = newTermName("isDefinedAt") diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index 7c4b797a08..16b4d590fa 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -353,7 +353,14 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer { /** A replacement for the standard typer's `typed1' method */ override protected def typed1(tree: Tree, mode: int, pt: Type): Tree = { - val tree1 = super.typed1(adaptMember(tree), mode, pt); +// var tree1 = try { //debug + var tree1 = super.typed1(adaptMember(tree), mode, pt); +// } catch { +// case ex: Throwable => +// if (settings.debug.value) +// System.out.println("exception when typing " + tree); +// throw ex +// } def adaptCase(cdef: CaseDef): CaseDef = { val body1 = adaptToType(cdef.body, tree1.tpe); copy.CaseDef(cdef, cdef.pat, cdef.guard, body1) setType body1.tpe diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index a864e571a4..b716c37114 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1922,6 +1922,7 @@ trait Typers requires Analyzer { def isApplicable(info: ImplicitInfo): boolean = !containsError(info.tpe) && !(isLocal && shadowed.contains(info.name)) && + (!isView || info.sym != Predef_identity) && tc.typedImplicit(pos, info, pt, isLocal) != EmptyTree def applicableInfos(is: List[ImplicitInfo]) = { val result = is filter isApplicable diff --git a/src/library/scala/BigInt.scala b/src/library/scala/BigInt.scala index 66d9719e88..a306a7a718 100644 --- a/src/library/scala/BigInt.scala +++ b/src/library/scala/BigInt.scala @@ -79,10 +79,7 @@ object BigInt { */ implicit def bigInt2ordered(x: BigInt): Ordered[BigInt] = new Ordered[BigInt] with Proxy { def self: Any = x; - def compare [b >: BigInt <% Ordered[b]](y: b): Int = y match { - case y: BigInt => x.bigInteger.compareTo(y.bigInteger) - case _ => -(y compare x) - } + def compare (y: BigInt): int = x.bigInteger.compareTo(y.bigInteger) } } diff --git a/src/library/scala/Enumeration.scala b/src/library/scala/Enumeration.scala index 5d44c60413..c484c5dc6a 100644 --- a/src/library/scala/Enumeration.scala +++ b/src/library/scala/Enumeration.scala @@ -115,11 +115,8 @@ abstract class Enumeration(initial: Int, names: String*) { protected final def Value(i: Int, name: String): Value = new Val(i, name); abstract class Value extends Ordered[Value] { - def id: Int; - override def compare[S >: Value <% Ordered[S]](that: S): Int = that match { - case that1: Value => id - that1.id - case _ => -(that compare this) - } + def id: Int; + override def compare(that: Value): Int = this.id - that.id } protected class Val(i: Int, name: String) extends Value { diff --git a/src/library/scala/Function1.scala b/src/library/scala/Function1.scala index efc056bd5f..aa6e114835 100644 --- a/src/library/scala/Function1.scala +++ b/src/library/scala/Function1.scala @@ -18,4 +18,6 @@ package scala trait Function1[-T0, +R] extends AnyRef { def apply(v0: T0): R override def toString() = "<function>" + def compose[A](g: A => T0): A => R = { x => apply(g(x)) } } + diff --git a/src/library/scala/Iterable.scala b/src/library/scala/Iterable.scala index 933d597b83..2a61ceaee4 100644 --- a/src/library/scala/Iterable.scala +++ b/src/library/scala/Iterable.scala @@ -14,6 +14,7 @@ package scala; import Predef.error; object Iterable { +/* implicit def view[A <% Ordered[A]](x: Iterable[A]): Ordered[Iterable[A]] = new Ordered[Iterable[A]] { def compare[B >: Iterable[A] <% Ordered[B]](that: B): Int = that match { @@ -31,7 +32,7 @@ object Iterable { -(that compare x) } } - +*/ /** The minimum element of a non-empty sequence of ordered elements */ def min[A <% Ordered[A]](seq: Iterable[A]): A = { val xs = seq.elements; diff --git a/src/library/scala/List.scala b/src/library/scala/List.scala index af3ebff450..1802a4b479 100644 --- a/src/library/scala/List.scala +++ b/src/library/scala/List.scala @@ -337,7 +337,6 @@ object List { else (xss map (xs => xs.head)) :: transpose(xss map (xs => xs.tail)); /** Lists with ordered elements are ordered - */ implicit def list2ordered[a <% Ordered[a]](x: List[a]): Ordered[List[a]] = new Ordered[List[a]] { def compare [b >: List[a] <% Ordered[b]](y: b): Int = y match { case y1: List[a] => compareLists(x, y1); @@ -354,7 +353,7 @@ object List { } } } - def view[a <% Ordered[a]](x: List[a]): Ordered[List[a]] = list2ordered(x); + */ } /** A class representing an ordered collection of elements of type @@ -366,7 +365,7 @@ object List { * @author Martin Odersky and others * @version 1.0, 16/07/2003 */ -sealed abstract class List[+a] extends Seq[a] { +sealed abstract class List[+a] extends Seq[a] with CaseClass { /** Returns true if the list does not contain any elements. * @return true, iff the list is empty. diff --git a/src/library/scala/Option.scala b/src/library/scala/Option.scala index c5820beedc..0577e66594 100644 --- a/src/library/scala/Option.scala +++ b/src/library/scala/Option.scala @@ -21,7 +21,7 @@ import Predef._ * @author Matthias Zenger * @version 1.0, 16/07/2003 */ -sealed abstract class Option[+A] extends Iterable[A] { +sealed abstract class Option[+A] extends Iterable[A] with CaseClass { def isEmpty: Boolean = this match { case None => true diff --git a/src/library/scala/Ordered.scala b/src/library/scala/Ordered.scala index 97639c5170..7b49e95d10 100644 --- a/src/library/scala/Ordered.scala +++ b/src/library/scala/Ordered.scala @@ -17,7 +17,7 @@ package scala; * @author Martin Odersky * @version 1.0, 23/04/2004 */ -trait Ordered[+a] { +trait Ordered[a] { /** Result of comparing `this' with operand `that'. * returns `x' where @@ -25,14 +25,11 @@ trait Ordered[+a] { * <code>x == 0</code> iff <code>this == that</code> * <code>x > 0</code> iff <code>this > that</code> */ - def compareTo [b >: a <% Ordered[b]](that: b): Int = compare(that) - def compare [b >: a <% Ordered[b]](that: b): Int; + def compare(that: a): Int; - def < [b >: a <% Ordered[b]](that: b): Boolean = (this compare that) < 0; - - def > [b >: a <% Ordered[b]](that: b): Boolean = (this compare that) > 0; - - def <= [b >: a <% Ordered[b]](that: b): Boolean = (this compare that) <= 0; - - def >= [b >: a <% Ordered[b]](that: b): Boolean = (this compare that) >= 0; + def < (that: a): Boolean = (this compare that) < 0 + def > (that: a): Boolean = (this compare that) > 0 + def <= (that: a): Boolean = (this compare that) <= 0 + def >= (that: a): Boolean = (this compare that) >= 0 + def compareTo(that: a): Int = compare(that) } diff --git a/src/library/scala/Predef.scala b/src/library/scala/Predef.scala index b98696d5b4..7d68adc79f 100644 --- a/src/library/scala/Predef.scala +++ b/src/library/scala/Predef.scala @@ -198,13 +198,7 @@ object Predef { implicit def int2ordered(x: int): Ordered[int] = new Ordered[int] with Proxy { def self: Any = x - def compare [b >: int <% Ordered[b]](y: b): int = y match { - case y1: int => - if (x < y1) -1 - else if (x > y1) 1 - else 0 - case _ => -(y compare x) - } + def compare (y: int): int = if (x < y) -1 else if (x > y) 1 else 0 } implicit def intWrapper(x: int) = new runtime.RichInt(x) @@ -213,207 +207,140 @@ object Predef { implicit def char2ordered(x: char): Ordered[char] = new Ordered[char] with Proxy { def self: Any = x - def compare [b >: char <% Ordered[b]](y: b): int = y match { - case y1: char => - if (x < y1) -1 - else if (x > y1) 1 - else 0 - case _ => -(y compare x) - } + def compare (y: char): int = if (x < y) -1 else if (x > y) 1 else 0 } implicit def byte2ordered(x: byte): Ordered[byte] = new Ordered[byte] with Proxy { def self: Any = x - def compare [b >: byte <% Ordered[b]](y: b): int = y match { - case y1: byte => - if (x < y1) -1 - else if (x > y1) 1 - else 0 - case _ => -(y compare x) - } + def compare (y: byte): int = if (x < y) -1 else if (x > y) 1 else 0 } implicit def short2ordered(x: short): Ordered[short] = new Ordered[short] with Proxy { def self: Any = x - def compare [b >: short <% Ordered[b]](y: b): int = y match { - case y1: short => - if (x < y1) -1 - else if (x > y1) 1 - else 0 - case _ => -(y compare x) - } + def compare (y: short): int = if (x < y) -1 else if (x > y) 1 else 0 } implicit def unit2ordered(x: unit): Ordered[unit] = new Ordered[unit] with Proxy { def self: Any = x - def compare [b >: unit <% Ordered[b]](y: b): int = y match { - case y1: unit => 0 - case _ => -(y compare x) - } + def compare (y: unit): int = 0 } implicit def long2ordered(x: long): Ordered[long] = new Ordered[long] with Proxy { def self: Any = x - def compare [b >: long <% Ordered[b]](y: b): int = y match { - case y1: long => - if (x < y1) -1 - else if (x > y1) 1 - else 0 - case _ => -(y compare x) - } + def compare (y: long) = if (x < y) -1 else if (x > y) 1 else 0 } implicit def float2ordered(x: float): Ordered[float] = new Ordered[float] with Proxy { def self: Any = x - def compare [b >: float <% Ordered[b]](y: b): int = y match { - case y1: float => - if (x < y1) -1 - else if (x > y1) 1 - else 0 - case _ => -(y compare x) - } + def compare (y: float) = if (x < y) -1 else if (x > y) 1 else 0 } implicit def double2ordered(x: double): Ordered[double] = new Ordered[double] with Proxy { def self: Any = x - def compare [b >: double <% Ordered[b]](y: b): int = y match { - case y1: double => - if (x < y1) -1 - else if (x > y1) 1 - else 0 - case _ => -(y compare x) - } + def compare (y: double) = if (x < y) -1 else if (x > y) 1 else 0 } implicit def boolean2ordered(x: boolean): Ordered[boolean] = new Ordered[boolean] with Proxy { def self: Any = x - def compare [b >: boolean <% Ordered[b]](y: b): int = y match { - case y1: boolean => - if (x == y1) 0 - else if (x) 1 - else -1 - case _ => -(y compare x) - } + def compare (y: boolean) = if (x == y) 0 else if (x) 1 else 0 } - implicit def seq2ordered[a <% Ordered[a]](xs: Array[a]): Ordered[Seq[a]] = - new Ordered[Seq[a]] with Proxy { + implicit def iterable2ordered[a <% Ordered[a]](xs: Iterable[a]): Ordered[Iterable[a]] = + new Ordered[Iterable[a]] with Proxy { val self = xs - def compare[b >: Seq[a] <% Ordered[b]](that: b): Int = that match { - case that: Seq[a] => - var res = 0 - val these = xs.elements - val those = that.elements - while (res == 0 && these.hasNext) - res = if (those.hasNext) these.next compare those.next else 1 - res - case _ => - -(that compare xs) + def compare (that: Iterable[a]) = { + var res = 0 + val these = xs.elements + val those = that.elements + while (res == 0 && these.hasNext) + res = if (those.hasNext) these.next compare those.next else 1 + res } } implicit def tuple22ordered[a1 <% Ordered[a1], a2 <% Ordered[a2]](x: Tuple2[a1, a2]): Ordered[Tuple2[a1, a2]] = new Ordered[Tuple2[a1, a2]] with Proxy { val self = x - def compare[T >: Tuple2[a1, a2] <% Ordered[T]](y: T): Int = y match { - case y: Tuple2[a1, a2] => - val res = x._1 compare y._1 - if (res == 0) x._2 compare y._2 - else res - case _ => -(y compare x) + def compare (y: Tuple2[a1, a2]): Int = { + val res = x._1 compare y._1 + if (res == 0) x._2 compare y._2 + else res } } implicit def tuple32ordered[a1 <% Ordered[a1], a2 <% Ordered[a2], a3 <% Ordered[a3]](x: Tuple3[a1, a2, a3]): Ordered[Tuple3[a1, a2, a3]] = new Ordered[Tuple3[a1, a2, a3]] with Proxy { val self = x - def compare[T >: Tuple3[a1, a2, a3] <% Ordered[T]](y: T): Int = y match { - case y: Tuple3[a1, a2, a3] => - val res = x._1 compare y._1 - if (res == 0) Tuple2(x._2, x._3) compare Tuple2(y._2, y._3) - else res - case _ => -(y compare x) + def compare (y: Tuple3[a1, a2, a3]): Int = { + val res = x._1 compare y._1 + if (res == 0) Tuple2(x._2, x._3) compare Tuple2(y._2, y._3) + else res } } implicit def tuple42ordered[a1 <% Ordered[a1], a2 <% Ordered[a2], a3 <% Ordered[a3], a4 <% Ordered[a4]](x: Tuple4[a1, a2, a3, a4]): Ordered[Tuple4[a1, a2, a3, a4]] = new Ordered[Tuple4[a1, a2, a3, a4]] with Proxy { val self = x - def compare[T >: Tuple4[a1, a2, a3, a4] <% Ordered[T]](y: T): Int = y match { - case y: Tuple4[a1, a2, a3, a4] => - val res = x._1 compare y._1 - if (res == 0) Tuple3(x._2, x._3, x._4) compare Tuple3(y._2, y._3, y._4) - else res - case _ => -(y compare x) + def compare (y: Tuple4[a1, a2, a3, a4]): Int = { + val res = x._1 compare y._1 + if (res == 0) Tuple3(x._2, x._3, x._4) compare Tuple3(y._2, y._3, y._4) + else res } } implicit def tuple52ordered[a1 <% Ordered[a1], a2 <% Ordered[a2], a3 <% Ordered[a3], a4 <% Ordered[a4], a5 <% Ordered[a5]](x: Tuple5[a1, a2, a3, a4, a5]): Ordered[Tuple5[a1, a2, a3, a4, a5]] = new Ordered[Tuple5[a1, a2, a3, a4, a5]] with Proxy { val self = x - def compare[T >: Tuple5[a1, a2, a3, a4, a5] <% Ordered[T]](y: T): Int = y match { - case y: Tuple5[a1, a2, a3, a4, a5] => - val res = x._1 compare y._1 - if (res == 0) Tuple4(x._2, x._3, x._4, x._5) compare Tuple4(y._2, y._3, y._4, y._5) - else res - case _ => -(y compare x) + def compare (y: Tuple5[a1, a2, a3, a4, a5]): Int = { + val res = x._1 compare y._1 + if (res == 0) Tuple4(x._2, x._3, x._4, x._5) compare Tuple4(y._2, y._3, y._4, y._5) + else res } } implicit def tuple62ordered[a1 <% Ordered[a1], a2 <% Ordered[a2], a3 <% Ordered[a3], a4 <% Ordered[a4], a5 <% Ordered[a5], a6 <% Ordered[a6]](x: Tuple6[a1, a2, a3, a4, a5, a6]): Ordered[Tuple6[a1, a2, a3, a4, a5, a6]] = new Ordered[Tuple6[a1, a2, a3, a4, a5, a6]] with Proxy { val self = x - def compare[T >: Tuple6[a1, a2, a3, a4, a5, a6] <% Ordered[T]](y: T): Int = y match { - case y: Tuple6[a1, a2, a3, a4, a5, a6] => - val res = x._1 compare y._1 - if (res == 0) Tuple5(x._2, x._3, x._4, x._5, x._6) compare Tuple5(y._2, y._3, y._4, y._5, y._6) - else res - case _ => -(y compare x) + def compare (y: Tuple6[a1, a2, a3, a4, a5, a6]): Int = { + val res = x._1 compare y._1 + if (res == 0) Tuple5(x._2, x._3, x._4, x._5, x._6) compare Tuple5(y._2, y._3, y._4, y._5, y._6) + else res } } implicit def tuple72ordered[a1 <% Ordered[a1], a2 <% Ordered[a2], a3 <% Ordered[a3], a4 <% Ordered[a4], a5 <% Ordered[a5], a6 <% Ordered[a6], a7 <% Ordered[a7]](x: Tuple7[a1, a2, a3, a4, a5, a6, a7]): Ordered[Tuple7[a1, a2, a3, a4, a5, a6, a7]] = new Ordered[Tuple7[a1, a2, a3, a4, a5, a6, a7]] with Proxy { val self = x - def compare[T >: Tuple7[a1, a2, a3, a4, a5, a6, a7] <% Ordered[T]](y: T): Int = y match { - case y: Tuple7[a1, a2, a3, a4, a5, a6, a7] => - val res = x._1 compare y._1 - if (res == 0) Tuple6(x._2, x._3, x._4, x._5, x._6, x._7) compare Tuple6(y._2, y._3, y._4, y._5, y._6, y._7) - else res - case _ => -(y compare x) + def compare (y: Tuple7[a1, a2, a3, a4, a5, a6, a7]): Int = { + val res = x._1 compare y._1 + if (res == 0) Tuple6(x._2, x._3, x._4, x._5, x._6, x._7) compare Tuple6(y._2, y._3, y._4, y._5, y._6, y._7) + else res } } implicit def tuple82ordered[a1 <% Ordered[a1], a2 <% Ordered[a2], a3 <% Ordered[a3], a4 <% Ordered[a4], a5 <% Ordered[a5], a6 <% Ordered[a6], a7 <% Ordered[a7], a8 <% Ordered[a8]](x: Tuple8[a1, a2, a3, a4, a5, a6, a7, a8]): Ordered[Tuple8[a1, a2, a3, a4, a5, a6, a7, a8]] = new Ordered[Tuple8[a1, a2, a3, a4, a5, a6, a7, a8]] with Proxy { val self = x - def compare[T >: Tuple8[a1, a2, a3, a4, a5, a6, a7, a8] <% Ordered[T]](y: T): Int = y match { - case y: Tuple8[a1, a2, a3, a4, a5, a6, a7, a8] => - val res = x._1 compare y._1 - if (res == 0) Tuple7(x._2, x._3, x._4, x._5, x._6, x._7, x._8) compare Tuple7(y._2, y._3, y._4, y._5, y._6, y._7, y._8) - else res - case _ => -(y compare x) + def compare (y: Tuple8[a1, a2, a3, a4, a5, a6, a7, a8]): Int = { + val res = x._1 compare y._1 + if (res == 0) Tuple7(x._2, x._3, x._4, x._5, x._6, x._7, x._8) compare Tuple7(y._2, y._3, y._4, y._5, y._6, y._7, y._8) + else res } } implicit def tuple92ordered[a1 <% Ordered[a1], a2 <% Ordered[a2], a3 <% Ordered[a3], a4 <% Ordered[a4], a5 <% Ordered[a5], a6 <% Ordered[a6], a7 <% Ordered[a7], a8 <% Ordered[a8], a9 <% Ordered[a9]](x: Tuple9[a1, a2, a3, a4, a5, a6, a7, a8, a9]): Ordered[Tuple9[a1, a2, a3, a4, a5, a6, a7, a8, a9]] = new Ordered[Tuple9[a1, a2, a3, a4, a5, a6, a7, a8, a9]] with Proxy { val self = x - def compare[T >: Tuple9[a1, a2, a3, a4, a5, a6, a7, a8, a9] <% Ordered[T]](y: T): Int = y match { - case y: Tuple9[a1, a2, a3, a4, a5, a6, a7, a8, a9] => - val res = x._1 compare y._1 - if (res == 0) Tuple8(x._2, x._3, x._4, x._5, x._6, x._7, x._8, x._9) compare Tuple8(y._2, y._3, y._4, y._5, y._6, y._7, y._8, y._9) - else res - case _ => -(y compare x) + def compare (y: Tuple9[a1, a2, a3, a4, a5, a6, a7, a8, a9]): Int = { + val res = x._1 compare y._1 + if (res == 0) Tuple8(x._2, x._3, x._4, x._5, x._6, x._7, x._8, x._9) compare Tuple8(y._2, y._3, y._4, y._5, y._6, y._7, y._8, y._9) + else res } } implicit def string2ordered(x: String): Ordered[String] = new Ordered[String] with Proxy { def self: Any = x - def compare [b >: String <% Ordered[b]](y: b): int = y match { - case y1: String => x compareTo y1 - case _ => -(y compare x) - } + def compare (y: String): int = x compareTo y } implicit def any2stringadd(x: String) = new runtime.StringAdd(x) diff --git a/src/library/scala/Seq.scala b/src/library/scala/Seq.scala index 51bb271453..5c04001c87 100644 --- a/src/library/scala/Seq.scala +++ b/src/library/scala/Seq.scala @@ -24,7 +24,7 @@ object Seq { override def isDefinedAt(x: Int): Boolean = (x == 0); def apply(i:Int) = x; // caller's responsibility to check isDefinedAt } - +/* implicit def view[A <% Ordered[A]](xs: Seq[A]): Ordered[Seq[A]] = new Ordered[Seq[A]] with Proxy { def self: Any = xs; @@ -41,6 +41,7 @@ object Seq { -(that compare xs) } } +*/ } diff --git a/src/library/scala/runtime/matching/Address.scala b/src/library/scala/runtime/matching/Address.scala index 56bab618a7..e8f09d50c9 100644 --- a/src/library/scala/runtime/matching/Address.scala +++ b/src/library/scala/runtime/matching/Address.scala @@ -24,11 +24,7 @@ class Address( l:Int* ) extends Ordered[Address] { private val list:List[Int] = l.toList; - def compare [b >: Address <% Ordered[b]](y: b): int = y match { - case o:Address => list.reverse.compare(o.list.reverse) - //(xs => List.view(xs)(Predef.int2ordered)); - case _ => -(y compare this) - } + def compare (y: Address): int = list.reverse.compare(y.list.reverse) def down: Address = new Address( ( 1 :: list ):_* ); diff --git a/src/library/scala/runtime/matching/NonTerm.scala b/src/library/scala/runtime/matching/NonTerm.scala index 5c005d3795..d97e3e94b3 100644 --- a/src/library/scala/runtime/matching/NonTerm.scala +++ b/src/library/scala/runtime/matching/NonTerm.scala @@ -35,11 +35,8 @@ case class TreeNT(i:int) extends NonTerm with Ordered[TreeNT] { this.vset = new immutable.TreeSet[Int]() incl vset ; } - def compare [b >: TreeNT <% Ordered[b]](y: b): int = y match { - case TreeNT( y1 ) => i compare y1; - case _ => -(y compare this) - } -}; + def compare (y: TreeNT): int = i compare y.i +} /** hedge nonterminals. holds nullable property. */ @@ -52,11 +49,8 @@ case class HedgeNT(i:int) extends NonTerm with Ordered[HedgeNT] { this.nullable = nullable; } - def compare [b >: HedgeNT <% Ordered[b]](y: b): int = y match { - case HedgeNT( y1 ) => i compare y1; - case _ => -(y compare this) - } -}; + def compare (y: HedgeNT): int = i compare y.i +} //case object EMPTYHEDGE extends HedgeNT( 0, true ) ; //case object ANYHEDGE extends HedgeNT( 1, true ) ; diff --git a/src/library/scala/runtime/matching/Rule.scala b/src/library/scala/runtime/matching/Rule.scala index 7e9e106727..b9a14d6063 100644 --- a/src/library/scala/runtime/matching/Rule.scala +++ b/src/library/scala/runtime/matching/Rule.scala @@ -15,15 +15,13 @@ package scala.runtime.matching ; /* hedge grammar rules */ abstract class Rule extends Ordered[Rule] { - def compare [b >: Rule <% Ordered[b]](that: b): int = that match { - case r:Rule => - if( rule_smaller( this, r ) ) - -1 - else if( rule_eq( this, r ) ) - 0 - else - 1 - case _ => -(that compare this) + def compare (that: Rule): int = { + if( rule_smaller( this, that ) ) + -1 + else if( rule_eq( this, that ) ) + 0 + else + 1 } final def rule_smaller( r1:Rule, r2:Rule ):boolean = r1 match { diff --git a/src/library/scala/util/automata/SubsetConstruction.scala b/src/library/scala/util/automata/SubsetConstruction.scala index 7a0cb4a39c..21fbaa3b87 100644 --- a/src/library/scala/util/automata/SubsetConstruction.scala +++ b/src/library/scala/util/automata/SubsetConstruction.scala @@ -20,8 +20,7 @@ class SubsetConstruction[T <: AnyRef](val nfa: NondetWordAutom[T]) { import immutable.{ BitSet, TreeMap, TreeSet } ; implicit def toOrdered(bs: BitSet): Ordered[BitSet] = new Ordered[BitSet] { - def compare [b >: BitSet <% Ordered[b]](other: b): Int = other match { - case that: BitSet => { + def compare (that: BitSet): Int = { val it1 = bs.elements; val it2 = that.elements; var res = 0; @@ -44,10 +43,9 @@ class SubsetConstruction[T <: AnyRef](val nfa: NondetWordAutom[T]) { if (it2.hasNext) res = -1; res - } + } //case _ => -(other.compare(this)) - } } /** the set {0} */ diff --git a/test/files/pos/viewtest3.scala b/test/files/pos/viewtest3.scala index 68277a7a47..aa7b2ec539 100644 --- a/test/files/pos/viewtest3.scala +++ b/test/files/pos/viewtest3.scala @@ -1,17 +1,18 @@ package testview; trait Tree[+a <% Ordered[a]] { - def insert[b >: a <% Ordered[b]](x: b): Tree[b]; + def insert[c >: b, b >: a <: c](x: b)(implicit d: c => Ordered[c]): 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 insert[c >: b, b >: a <: c](x: b)(implicit d: c => Ordered[c]): 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] = + def insert[c >: b, b >: a <: c](x: b)(implicit d: c => Ordered[c]): 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); |