いろいろ備忘録

雑記です。

(implicit s: Show[A])

def log[A](a: A)(implicit s: Show[A]) = println(s.show(a))

この(implicit s: Show[A])はカリー化とimplicitを両方使った結果。

もしlog[Int](3)とすると、
引数sが渡されていない、かつimplicitなので、
Intが引数で、かつimplictなShowメソッドを探す。

implicit val intShow = new Show[Int] {
def show(i:Int) = i
}

こんなのが見つかったら、それを先程のsに当てはめる。

Scalaの型クラス(typeclass)の分かりやすい説明(Cats公式翻訳) - Qiita