--- a/progs/lecture4.scala Thu Dec 08 22:19:21 2022 +0000
+++ b/progs/lecture4.scala Sat Dec 17 12:42:49 2022 +0000
@@ -124,7 +124,7 @@
def length_int_list(lst: List[Int]): Int = lst match {
case Nil => 0
- case x::xs => 1 + length_int_list(xs)
+ case _::xs => 1 + length_int_list(xs)
}
length_int_list(List(1, 2, 3, 4))
@@ -146,7 +146,8 @@
length(List("1", "2", "3", "4"))
length(List(1, 2, 3, 4))
-length[Int](List(1, 2, 3, 4))
+
+length[String](List(1, 2, 3, 4))
def map[A, B](lst: List[A], f: A => B): List[B] = lst match {
@@ -541,12 +542,14 @@
// you can avoid ugly fudges, like a MyString, by
// using implicit conversions.
+print("\n")
+print("""\n""")
implicit class MyString(s: String) {
def increment = s.map(c => (c + 1).toChar)
}
-"HAL".increment.map(_.toInt)
+"HAL".increment
// Abstract idea: