--- a/progs/lecture2.scala Thu Dec 01 17:08:02 2016 +0000
+++ b/progs/lecture2.scala Thu Dec 01 17:08:12 2016 +0000
@@ -180,9 +180,6 @@
-
-
-
def my_flatten(lst: List[Option[Int]]): List[Int] = lst match {
case Nil => Nil
case None::xs => my_flatten(xs)
@@ -200,6 +197,20 @@
get_me_a_string(0)
+// you can also have cases combined
+def season(month: String) = month match {
+ case "March" | "April" | "May" => "It's spring"
+ case "June" | "July" | "August" => "It's summer"
+ case "September" | "October" | "November" => "It's autumn"
+ case "December" | "January" | "February" => "It's winter"
+}
+
+println(season("November"))
+
+// What happens if no case matches?
+
+println(season("foobar"))
+
// User-defined Datatypes
//========================
--- a/progs/lecture3.scala Thu Dec 01 17:08:02 2016 +0000
+++ b/progs/lecture3.scala Thu Dec 01 17:08:12 2016 +0000
@@ -116,9 +116,17 @@
searchT(111, junk_coins, start_acc)
searchT(111111, junk_coins, start_acc)
-// moral: whenever a recursive function is resource-critical
-// (i.e. works on large recursion depth), then you need to
-// write it in tail-recursive fashion
+// Moral: Whenever a recursive function is resource-critical
+// (i.e. works with large recursion depths), then you need to
+// write it in tail-recursive fashion.
+//
+// Unfortuantely, the Scala is because of current limitations in
+// the JVM not as clever as other functional languages. It can
+// only optimise "self-tail calls". This excludes the cases of
+// multiple functions making tail calls to each other. Well,
+// nothing is perfect.
+
+
// Polymorphic Types