in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters.
<console>:7: error: type mismatch; found : java.lang.String("1") required: Int val num: Int = "1" ^ scala> implicit def string2int(s: String) = s.toInt string2int: (s: String)Int scala> val num: Int = "1" num: Int = 1
{ def cry() = "nya-nya-" } class Person { def punch[A <: {def cry(): String}](t: A) = t.cry } val person = new Person println(person.punch(new Dog)) println(person.punch(new Cat)) Scala Structural Subtyping
cry "nya-nya-" end end class Person def punch(t) t.cry end end person = Person.new puts person.punch(Dog.new) puts person.punch(Cat.new) Ruby Duck Typing