2 ms·
It's implicit arguments, not implicit conversions that enable type classes in Scala, although the class is usually represented by a trait e.g. trait Show[T
by lkitching 9y ago
It's implicit arguments, not implicit conversions that enable type classes in Scala, although the class is usually represented by a trait e.g.
trait Show[T] { def show(v : T): String }
implicit object ShowInt extends Show[Int] {
def show(i: Int) = i.toString
}
def showLine[T](v : T)(implicit show: Show[T]): Unit = {
println(show.show(v))
}
- daxfohl 9y agoNice, that makes it more clear. Thanks!