I want to implement the simplest typeclass example.
Here I come : my typeclass is just a regular scala trait
scala> trait Show[A] { def show(a: A) : String }
defined trait Show
Here is an instance of my typeclass for type Int
scala> implicit val IntShow = new Show[Int] { def show(i: Int) = s"'$i' is an int" }
IntShow: Show[Int] = $anon$1@14459d53
Here is a client code that uses my typeclass
scala> def f[A](a:A)(implicit s : Show[A]) = println(s.show(a))
f: [A](a: A)(implicit s: Show[A])Unit
Let's call it
scala> f(1)
'1' is an int
Could it be simpler ?