scala/recs.scala
changeset 194 fc2a5e9fbb97
parent 193 317a2532c567
child 195 f06aa4e1c25b
--- a/scala/recs.scala	Thu Feb 21 16:07:40 2013 +0000
+++ b/scala/recs.scala	Fri Feb 22 14:31:34 2013 +0000
@@ -1,32 +1,37 @@
 package object recs {
 
+//Recursive Functions
 
-//Recursive Functions
 abstract class Rec {
   def eval(ns: List[Int]) : Int
 }
+
 case object Z extends Rec {
   override def eval(ns: List[Int]) = ns match {
     case n::Nil => 0
     case _ => throw new IllegalArgumentException("Z: args")
   }
 } 
+
 case object S extends Rec {
   override def eval(ns: List[Int]) = ns match {
     case n::Nil => n + 1
     case _ => throw new IllegalArgumentException("S: args")
   }
 } 
+
 case class Id(n: Int, m: Int) extends Rec {
   override def eval(ns: List[Int]) = 
     if (ns.length == n && m < n) ns(m)
     else throw new IllegalArgumentException("Id: args")
 }
+
 case class Cn(n: Int, f: Rec, gs: List[Rec]) extends Rec {
   override def eval(ns: List[Int]) = 
     if (ns.length == n) f.eval(gs.map(_.eval(ns)))
     else throw new IllegalArgumentException("Cn: args")
 }
+
 case class Pr(n: Int, f: Rec, g: Rec) extends Rec {
   override def eval(ns: List[Int]) = 
     if (ns.length == n - 1) {
@@ -38,6 +43,7 @@
     }
     else throw new IllegalArgumentException("Cn: args")
 }
+
 case class Mn(n: Int, f: Rec) extends Rec {
   override def eval(ns: List[Int]) = 0