From b004c3ddb38f8e690a0895a51ad0c83ff57a01e7 Mon Sep 17 00:00:00 2001 From: Den Shabalin Date: Wed, 13 Nov 2013 15:33:33 +0100 Subject: deprecate Pair and Triple --- test/files/presentation/callcc-interpreter.check | 8 +++--- .../callcc-interpreter/src/CallccInterpreter.scala | 32 ++++++++++++---------- 2 files changed, 22 insertions(+), 18 deletions(-) (limited to 'test/files/presentation') diff --git a/test/files/presentation/callcc-interpreter.check b/test/files/presentation/callcc-interpreter.check index f031c52c86..1f868097ca 100644 --- a/test/files/presentation/callcc-interpreter.check +++ b/test/files/presentation/callcc-interpreter.check @@ -1,8 +1,8 @@ reload: CallccInterpreter.scala -askTypeCompletion at CallccInterpreter.scala(51,38) +askTypeCompletion at CallccInterpreter.scala(51,34) ================================================================================ -[response] askTypeCompletion at (51,38) +[response] askTypeCompletion at (51,34) retrieved 59 members abstract trait Term extends AnyRef abstract trait Value extends AnyRef @@ -83,8 +83,8 @@ def showM(m: callccInterpreter.M[callccInterpreter.Value]): String = m.in.apply( askType at CallccInterpreter.scala(50,30) ================================================================================ [response] askTypeAt (50,30) -def add(a: callccInterpreter.Value, b: callccInterpreter.Value): callccInterpreter.M[_ >: callccInterpreter.Num with callccInterpreter.Wrong.type <: Product with Serializable with callccInterpreter.Value] = scala.this.Predef.Pair.apply[callccInterpreter.Value, callccInterpreter.Value](a, b) match { - case scala.this.Predef.Pair.unapply[callccInterpreter.Value, callccInterpreter.Value]() ((n: Int)callccInterpreter.Num((m @ _)), (n: Int)callccInterpreter.Num((n @ _))) => this.unitM[callccInterpreter.Num](callccInterpreter.this.Num.apply(m.+(n))) +def add(a: callccInterpreter.Value, b: callccInterpreter.Value): callccInterpreter.M[_ >: callccInterpreter.Num with callccInterpreter.Wrong.type <: Product with Serializable with callccInterpreter.Value] = scala.Tuple2.apply[callccInterpreter.Value, callccInterpreter.Value](a, b) match { + case (_1: callccInterpreter.Value, _2: callccInterpreter.Value)(callccInterpreter.Value, callccInterpreter.Value)((n: Int)callccInterpreter.Num((m @ _)), (n: Int)callccInterpreter.Num((n @ _))) => this.unitM[callccInterpreter.Num](callccInterpreter.this.Num.apply(m.+(n))) case _ => callccInterpreter.this.unitM[callccInterpreter.Wrong.type](callccInterpreter.this.Wrong) } ================================================================================ diff --git a/test/files/presentation/callcc-interpreter/src/CallccInterpreter.scala b/test/files/presentation/callcc-interpreter/src/CallccInterpreter.scala index ce3b996b96..d498fe0b17 100644 --- a/test/files/presentation/callcc-interpreter/src/CallccInterpreter.scala +++ b/test/files/presentation/callcc-interpreter/src/CallccInterpreter.scala @@ -40,15 +40,15 @@ object callccInterpreter { override def toString() = "" } - type Environment = List[Pair[Name, Value]] + type Environment = List[Tuple2[Name, Value]] def lookup(x: Name, e: Environment): M[Value] = e match { case List() => unitM(Wrong) - case Pair(y, b) :: e1 => if (x == y) unitM(b) else lookup(x, e1) + case (y, b) :: e1 => if (x == y) unitM(b) else lookup(x, e1) } - def add(a: Value, b: Value) /*?*/ = Pair(a, b) match { - case Pair(Num(m), Num(n)) => this./*!*/unitM(Num(m + n)) + def add(a: Value, b: Value) /*?*/ = (a, b) match { + case (Num(m), Num(n)) => this./*!*/unitM(Num(m + n)) case _ => unitM(Wrong) } @@ -60,16 +60,20 @@ object callccInterpreter { def interp(t: Term, e: Environment): M[Value] = t match { case Var(x) => lookup(x, e) case Con(n) => unitM(Num(n)) - case Add(l, r) => for (val a <- interp(l, e); - val b <- interp(r, e); - val c <- add(a, b)) - yield c - case Lam(x, t) => unitM(Fun(a => interp(t, Pair(x, a) :: e))) - case App(f, t) => for (val a <- interp(f, e); - val b <- interp(t, e); - val c <- apply(a, b)) - yield c - case Ccc(x, t) => callCC(k => interp(t, Pair(x, Fun(k)) :: e)) + case Add(l, r) => + for { + a <- interp(l, e) + b <- interp(r, e) + c <- add(a, b) + } yield c + case Lam(x, t) => unitM(Fun(a => interp(t, (x, a) :: e))) + case App(f, t) => + for { + a <- interp(f, e) + b <- interp(t, e) + c <- apply(a, b) + } yield c + case Ccc(x, t) => callCC(k => interp(t, (x, Fun(k)) :: e)) } def test(t: Term): String = showM(interp(t, List())) -- cgit v1.2.3