summaryrefslogtreecommitdiff
path: root/docs/examples
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2007-03-23 16:17:43 +0000
committerIulian Dragos <jaguarul@gmail.com>2007-03-23 16:17:43 +0000
commite06381565db6615dfc0d384b76fd332ff93c6299 (patch)
treef6f9a6721e27bf30de40d5256150f5ccbd3a9b03 /docs/examples
parentb809bf2730a76316082b1e5ba8e6dcef48e7bbc3 (diff)
downloadscala-e06381565db6615dfc0d384b76fd332ff93c6299.tar.gz
scala-e06381565db6615dfc0d384b76fd332ff93c6299.tar.bz2
scala-e06381565db6615dfc0d384b76fd332ff93c6299.zip
Fixed compilation errors in distribution examples.
Diffstat (limited to 'docs/examples')
-rw-r--r--docs/examples/expressions/expressions-current.scala6
-rw-r--r--docs/examples/maps.scala6
-rw-r--r--docs/examples/monads/callccInterpreter.scala2
-rw-r--r--docs/examples/typeinf.scala10
-rw-r--r--docs/examples/xml/phonebook/phonebook3.scala21
5 files changed, 25 insertions, 20 deletions
diff --git a/docs/examples/expressions/expressions-current.scala b/docs/examples/expressions/expressions-current.scala
index 5eeb439430..660a417c11 100644
--- a/docs/examples/expressions/expressions-current.scala
+++ b/docs/examples/expressions/expressions-current.scala
@@ -1,5 +1,7 @@
package examples.expressions
+class Ref[a](var elem:a) {}
+
abstract class Lang {
trait Visitor {
def caseNum(n: int): unit
@@ -21,7 +23,7 @@ abstract class Lang {
}
abstract class Lang2 extends Lang {
- abstract class Visitor2 extends Visitor {
+ trait Visitor2 extends Visitor {
def casePlus(left: Exp, right: Exp): unit
}
@@ -32,7 +34,7 @@ abstract class Lang2 extends Lang {
}
// class Eval2(result: Ref[int]): visitor extends Eval(result) with Visitor2 {
- class Eval2(result: Ref[int]) requires visitor extends Visitor2 {
+ class Eval2(result: Ref[int]) requires visitor extends Eval(result) with Visitor2 {
def casePlus(l: Exp, r: Exp) =
result.elem = { l.visit(this); result.elem } + { r.visit(this); result.elem }
}
diff --git a/docs/examples/maps.scala b/docs/examples/maps.scala
index 5b1af51ac3..504966cf81 100644
--- a/docs/examples/maps.scala
+++ b/docs/examples/maps.scala
@@ -15,7 +15,7 @@ object maps {
val empty: map
}
- class AlgBinTree[kt <: Ordered[kt], vt <: AnyRef]() extends MapStruct[kt, vt] {
+ class AlgBinTree[kt >: AllRef <: Ordered[kt], vt >: AllRef <: AnyRef]() extends MapStruct[kt, vt] {
type map = AlgMap
val empty: AlgMap = Empty()
@@ -65,7 +65,7 @@ object maps {
}
}
- class OOBinTree[kt <: Ordered[kt], vt <: AnyRef]() extends MapStruct[kt, vt] {
+ class OOBinTree[kt >: AllRef <: Ordered[kt], vt >: AllRef <: AnyRef]() extends MapStruct[kt, vt] {
type map = OOMap
trait OOMap extends Map {
@@ -105,7 +105,7 @@ object maps {
}
}
- class MutBinTree[kt <: Ordered[kt], vt <: AnyRef]() extends MapStruct[kt, vt] {
+ class MutBinTree[kt >: AllRef <: Ordered[kt], vt >: AllRef <: AnyRef]() extends MapStruct[kt, vt] {
type map = MutMap
class MutMap(key: kt, value: vt) extends Map {
val k = key
diff --git a/docs/examples/monads/callccInterpreter.scala b/docs/examples/monads/callccInterpreter.scala
index 934fce1a9e..a0b16738c6 100644
--- a/docs/examples/monads/callccInterpreter.scala
+++ b/docs/examples/monads/callccInterpreter.scala
@@ -1,5 +1,7 @@
object callccInterpreter {
+ def id[a](x: a) = x
+
type Answer = Value;
case class M[A](in: (A => Answer) => Answer) {
diff --git a/docs/examples/typeinf.scala b/docs/examples/typeinf.scala
index f21d514f87..f2dd252ff7 100644
--- a/docs/examples/typeinf.scala
+++ b/docs/examples/typeinf.scala
@@ -172,7 +172,7 @@ object typeInfer {
for (val s <- id; s != "let" && s != "in") yield s
/** term = '\' ident '.' term | term1 {term1} | let ident "=" term in term */
- def term: Parser[Term] =
+ def term: Parser[Term] = (
( for (
val _ <- wschr('\\');
val x <- ident;
@@ -193,9 +193,10 @@ object typeInfer {
val t <- term1;
val ts <- rep(term1))
yield (t /: ts)((f, arg) => App(f, arg)) )
+ )
/** term1 = ident | '(' term ')' */
- def term1: Parser[Term] =
+ def term1: Parser[Term] = (
( for (val s <- ident)
yield Var(s): Term )
|||
@@ -203,7 +204,8 @@ object typeInfer {
val _ <- wschr('(');
val t <- term;
val _ <- wschr(')'))
- yield t );
+ yield t )
+ )
/** all = term ';' */
def all: Parser[Term] =
@@ -214,7 +216,7 @@ object typeInfer {
}
class ParseString(s: String) extends Parsers {
- type intype = int
+ type inputType = int
val input = 0
def any = new Parser[char] {
def apply(in: int): Parser[char]#Result =
diff --git a/docs/examples/xml/phonebook/phonebook3.scala b/docs/examples/xml/phonebook/phonebook3.scala
index ec49d450f4..cd02490696 100644
--- a/docs/examples/xml/phonebook/phonebook3.scala
+++ b/docs/examples/xml/phonebook/phonebook3.scala
@@ -14,8 +14,8 @@ object phonebook3 {
/** returns true if this element's first child is the right 'name'
* x is treated a if it was a singleton sequence here.
*/
- def hasName ( x: Seq[Node] ) = x(0).child.elements.next match {
- case <name>{ Text(Name) }</name> => true
+ def hasName ( x: Seq[Node] ) = x(0).child.elements.exists {
+ case <name>{Text(Name)}</name> => true
case _ => false
}
@@ -41,12 +41,12 @@ object phonebook3 {
/** walks through tree, returns changed/copied updated tree */
def copyOrChange ( ch: Iterator[Node] ):List[Node] = {
- for( val c <- ch ) yield c match {
+ for( val c <- ch ) yield c match {
- case x @ <entry>{ ch1 @ _* }</entry> if hasName( x ) =>
+ case x @ <entry>{ ch1 @ _* }</entry> if hasName(x) =>
val it = ch1.elements;
val nameElem:Seq[Node] = it.next; // grab 'name' element
- val ch2 = nameElem concat copyOrChange( it ); // concat with updated seq
+ val ch2 = nameElem ++ copyOrChange( it ); // concat with updated seq
if( ch1 == ch2 ) // not present: add as first entry
@@ -63,13 +63,12 @@ object phonebook3 {
</entry>
case y @ <phone>{ _* }</phone> if hasWhere( y ) =>
- Console.println("c = "+c);
- <phone where={ Where }>{ newPhone }</phone>
+ Console.println("phone: "+c);
+ <phone where={ Where }>{ newPhone }</phone>
- case _ =>
- Console.println("c = "+c);
- Console.println("c.attributes= "+c.attributes);
- c
+ case _ =>
+ Console.println("default "+c);
+ c
}
}.toList ; // for ... yield ... returns Iterator, convert to list