Sample code from Type classes in Scala
object TypeClasses0 {
trait Show[A] {
def show(a: A): String
}
object Show {
val intCanShow: Show[Int] = new Show[Int] {
def show(int: Int) = s"int $int"
}
}
def main(args: Array[String]): Unit = {
import Show._
println( intCanShow.show(20) )
}
}