progs/lecture3.scala
changeset 223 c6453f3547ec
parent 218 22705d22c105
child 318 029e2862bb4e
--- a/progs/lecture3.scala	Fri Nov 30 03:44:27 2018 +0000
+++ b/progs/lecture3.scala	Fri Nov 30 07:54:49 2018 +0000
@@ -515,70 +515,5 @@
 
 
 
-// Polymorphic Types
-//===================
-
-// You do not want to write functions like contains, first 
-// and so on for every type of lists.
 
 
-def length_string_list(lst: List[String]): Int = lst match {
-  case Nil => 0
-  case x::xs => 1 + length_string_list(xs)
-}
-
-def length_int_list(lst: List[Int]): Int = lst match {
-  case Nil => 0
-  case x::xs => 1 + length_int_list(xs)
-}
-
-length_string_list(List("1", "2", "3", "4"))
-length_int_list(List(1, 2, 3, 4))
-
-//-----
-def length[A](lst: List[A]): Int = lst match {
-  case Nil => 0
-  case x::xs => 1 + length(xs)
-}
-length(List("1", "2", "3", "4"))
-length(List(1, 2, 3, 4))
-
-def map[A, B](lst: List[A], f: A => B): List[B] = lst match {
-  case Nil => Nil
-  case x::xs => f(x)::map_int_list(xs, f) 
-}
-
-map_int_list(List(1, 2, 3, 4), square)
-
-
-
-
-
-
-// Cool Stuff
-//============
-
-
-// Implicits 
-//===========
-//
-// For example adding your own methods to Strings:
-// Imagine you want to increment strings, like
-//
-//     "HAL".increment
-//
-// you can avoid ugly fudges, like a MyString, by
-// using implicit conversions.
-
-
-implicit class MyString(s: String) {
-  def increment = for (c <- s) yield (c + 1).toChar 
-}
-
-"HAL".increment
-
-
-
-
-
-