scala/lib.scala
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Thu, 28 Feb 2013 15:21:43 +0000
changeset 204 e55c8e5da49f
parent 193 317a2532c567
child 221 18905d086cbb
permissions -rw-r--r--
updated proofs in Recursive (by Jian)

package object lib {

//some list functions
def tl[A](xs: List[A]) : List[A] = xs match {
  case Nil => Nil
  case x::xs => xs
}

def hd[A](xs: List[A]) : A = xs.head

def nth_of[A](xs: List[A], n: Int) = 
  if (n <= xs.length) Some(xs(n)) else None 

//some map functions
def dget(m: Map[Int, Int], n: Int) = m.getOrElse(n, 0)

//some string functions
def join[A](xs: List[A]) = xs.foldLeft("")(_.toString + _)

}