diff options
author | Paul Phillips <paulp@improving.org> | 2010-10-02 22:43:10 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-10-02 22:43:10 +0000 |
commit | 06aa1c9eff49d5190e82a72a876d7b3bd706d6d4 (patch) | |
tree | 4c38f2559c839ba297060a48023d69550c5d107e /test/pending/pos/unappgadteval.scala | |
parent | 256aca612204f1316e5281af6d10a14300d58ad1 (diff) | |
download | scala-06aa1c9eff49d5190e82a72a876d7b3bd706d6d4.tar.gz scala-06aa1c9eff49d5190e82a72a876d7b3bd706d6d4.tar.bz2 scala-06aa1c9eff49d5190e82a72a876d7b3bd706d6d4.zip |
Sorting through the tests in pending from oldes...
Sorting through the tests in pending from oldest to newest because I
don't believe in having useless appendages. The verdict on the oldest
fifteen tests is: 15/15 are fixed. Many were already in files under a
different name. I moved a few and deleted the rest. Fun fact of the
day: apparently there was a time when to call into java varargs with no
arguments you might have to write something like:
getClass().getMethod("getCount", Array[java.lang.Class[T] forSome { type T }]())
On this basis I retract any complaints I've ever had about anything.
There is one question mark outlined in pos/testCoercionThis.scala, a
file formerly called pos/moors.scala and therefore... review by moors.
Diffstat (limited to 'test/pending/pos/unappgadteval.scala')
-rw-r--r-- | test/pending/pos/unappgadteval.scala | 78 |
1 files changed, 60 insertions, 18 deletions
diff --git a/test/pending/pos/unappgadteval.scala b/test/pending/pos/unappgadteval.scala index 0c22c71dee..fce54723a1 100644 --- a/test/pending/pos/unappgadteval.scala +++ b/test/pending/pos/unappgadteval.scala @@ -1,19 +1,29 @@ -//Class hierarchy +/** Cleaned up in october 2010 by paulp. + * Hey, we should get this working. + */ + +// Class hierarchy trait Term[a] + object Var{ def unapply[a](x:Var[a]) = Some(x.name) } class Var[a] (val name : String) extends Term[a] + object Num{ def unapply(x:Num) = Some(x.value) } -class Num (val value : int) extends Term[int] -object Lam{ def unapply[b,c](l:Lam[b,c]) = Some{l.x,l.e}} -class Lam[b, c] (val x : Var[b], val e : Term[c]) extends Term[b => c] -object App{ def unapply[b,c](a:App[b,c]) = Some{a.f,a.e}} +class Num (val value : Int) extends Term[Int] + +object Lam{ def unapply[b,c](l: Lam[b,c]) = Some(l.x, l.e) } +class Lam[b, c](val x : Var[b], val e : Term[c]) extends Term[b => c] + +object App{ def unapply[b,c](a: App[b,c]) = Some(a.f, a.e) } class App[b, c] (val f : Term[b => c], val e : Term[b]) extends Term[c] -object Suc{ def unapply(a:Suc) = true } -class Suc () extends Term[int => int] + +object Suc { def unapply(a: Suc) = true } +class Suc() extends Term[Int => Int] + // Environments : abstract class Env { - def apply[a](v : Var[a]): a - def extend[a](v : Var[a], x : a) = new Env { + def apply[a](v: Var[a]): a + def extend[a](v: Var[a], x : a) = new Env { def apply[b](w: Var[b]): b = w match { case _ : v.type => x // v eq w, hence a = b case _ => Env.this.apply(w) @@ -21,15 +31,47 @@ abstract class Env { } object empty extends Env { - def apply[a](x : Var[a]): a = throw new Error("not found : "+x.name) + def apply[a](x: Var[a]): a = throw new Error("not found : "+x.name) } + object Test { -// Evaluation : -def eval[a](t : Term[a], env : Env): a = t match { - case v : Var[b] => env(v) // a = b - case n @ Num(value) => value // a = int - case i @ Suc() => { y: int => y + 1 } // a = int=>int - case f @ Lam[b,c](x,e) => { y: b => eval(e, env.extend(x, y))} // a = b=>c - case a @ App(f,e) => eval(f, env)(eval(e, env)) // a = c -} + val v1 = new Var[util.Random]("random") + val v2 = new Var[Int]("Int") + val v3 = new Var[List[String]]("list") + + val anEnv = (empty + .extend(v1, new util.Random) + .extend(v2, 58) + .extend(v3, Nil) + ) + + def eval[a](t: Term[a], env : Env): a = t match { + // First three work + case v : Var[b] => env(v) // a = b + case n @ Num(value) => value // a = Int + case a @ App(f,e) => eval(f, env)(eval(e, env)) // a = c + + // Next one fails like: + // + // found : (Int) => Int + // required: a + case i @ Suc() => { (y: Int) => y + 1 } // a = Int => Int + + // Next one fails like: + // + // error: '=>' expected but '[' found. + // case f @ Lam[b,c](x, e) => { (y: b) => eval(e, env.extend(x, y)) } // a = b=>c + // ^ + case f @ Lam[b,c](x, e) => { (y: b) => eval(e, env.extend(x, y)) } // a = b=>c + } + + val f1 = () => eval(v1, anEnv) + val f2 = () => eval(v2, anEnv) + val f3 = () => eval(v3, anEnv) + + def main(args: Array[String]): Unit = { + println(f1()) + println(f2()) + println(f3()) + } } |