Scala 詭異語法筆記
Function type 其實是一個 trait,
trait Function1[-T, +R] extends AnyRef {
def apply(v1: T): R
}
而 anonymous function 就是以類似這樣的手法來實作的:
val f = new Function1[Int, Int] {
def apply(x: Int) = x + 1
}
而 Scala 有一個特殊寫法,Function1[Int, Int] 可以寫成 (Int Function1 Int)。
http://stephen-tu.blogspot.com/2010/09/another-use-of-scalas-implicit-values.html
這裡用到了一大堆技巧,implicit parameter, implicit conversion, …